androiddata-bindingandroid-databindingandroid-lifecyclefragment-lifecycle

Is it mandatory to set databinding obejct to null inside onDestroyView()?


I read some articles where it is said that the best practice is to set databinding obejct to null inside onDestroyView() in a fragment:

override fun onDestroyView() {
    super.onDestroyView()
    dataBinding = null
}

I've also seen this video where this practice is not even mentioned. I personally don't understand if this practice makes sense or not. Please provide some info about this issue because I really don't know how to go further. Thanks


Solution

  • This is not necessary. databinding is just auto generated by compile system. You can go to see the generated source code. Just use databinding object as same as common propertys.