Max Kohne
Aug 10, 2021

The problem with initializing lazily is that the lazy binding property will be kept in memory even after onDestroyView is called. This will prevent it from being garbage collected which will then cause a memory leak.

As you pointed out, the critical part of the delegate is that it has lifecycle observers to properly null out the ViewBinding property so it doesn't leak. The other good part about the delegate solution is that it is nulled out automatically for you, so you don't have to think about it as a developer.

Let me know if that answered your question or if I can clarify it better.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Max Kohne
Max Kohne

Written by Max Kohne

Ex-Staff Android Software Engineer at Procore Technologies.

Responses (1)

Write a response