Pick the fix
A Fragment keeps private lateinit var binding and LeakCanary reports the old view tree after navigating back. Fix?
Hint 1 of 1
When does a Fragment's view die?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Use a nullable _binding set in onCreateView and cleared in onDestroyView
Correct. The Fragment instance outlives its view on the back stack.
Why not the others?
- B Switch to Data Binding. Same leak if the binding is kept.
- C Call binding.unbind() in onDestroy. onDestroy is too late; the view was destroyed earlier.
- D Make the binding a companion object. That's a global leak.