Archie
05/18/2020, 7:14 AMViewBinding .
In the documentation here, it suggest to clear the binding reference, in on onDestroyView() :
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
because:
"Note: Fragments outlive their views. Make sure you clean up any references to the binding class instance in the fragment's onDestroyView() method."
My questions are:
1. When exactly would the fragment outlive the views? Is it when the fragment is added to the backstack?
2. Does avoiding a global reference to the _binding and simply referencing it locally in onViewCreated() ensures that I wont leak the viewBinding? ex.
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val binding = SomeViewBinding.inflate(view)
}