*Why is it important to clear the `binding` in `on...
# android
v
Why is it important to clear the 
binding
 in 
onDestroyView
 when implementing Android View Binding in a Fragment?
😶 4
n
Because if you won’t clear it memory leak will happen. There are a lot of approaches and even libraries. You can search over google
u
You may use lazy delegates
1
v
@Nikolay Puliaev do you have better approach
@Umar Ata how can i achieve that ?
u
val viewBinding : MyFragmentBinding by lazy { MyFragmentBinding.inlfate(layoutInflator) }
👎🏻 1
👎 2
u
Something like this
v
Thanks a million
u
@FunkyMuse Hi You marked my suggestion as X Can you please add some details?
o
w
FunkyMuse didn’t weigh in, but I can- Lazy isn’t Weak, I’m pretty sure that Lazy would still cause a leak.
Unless you never accessed it. Which would kinda defeat the point.
f
As Will Shelor said
u
Do you guys have any documentation for the leak on lazy delegates I am actually using it and if your statement is true that it also leak so I need to change it in many places Please provide any documentation that proves your words @FunkyMuse @Will Shelor
f
Fragments have 2 lifecycles, one for the Fragment itself and one for the View of the Fragment, using Lazy means that your view will be alive as long as your Fragment object is alive