title: Android View Binding - Clear Binding in Fragment Lifecycle
body: <p><strong>Why is it important to clear the <code>binding</code> in <code>onDestroyView</code> when implementing <em><a href="https://developer.android.com/topic/libraries/view-binding" rel="noreferrer">Android View Binding</a></em> in a Fragment?</strong></p>
  <p>As the documentation shows, <em><a href="https://developer.android.com/topic/libraries/view-binding#fragments" rel="noreferrer">Use view binding in fragments</a></em>, and the Android Architecture Components <em><a href="https://github.com/android/architecture-components-samples/blob/master/ViewBindingSample/app/src/main/java/com/android/example/viewbindingsample/BindFragment.kt#L36-L41" rel="noreferrer">sample</a></em>, the <code>binding</code> is initiated in <code>onCreateView</code>, and cleared in <code>onDestroyView</code>.</p>
  <p>What is the benefit of implementing this compared to initiating the <code>binding</code> without clearing it in <code>onDestroyView</code>? Without explicitly clearing the instance variable <code>binding</code>, it should be cleared when the Fragment is destroyed.</p>
  <pre><code>private var _binding: ResultProfileBinding? = null
  // This property is only valid between onCreateView and
  // onDestroyView.
  private val binding get() = _binding!!
  
  override fun onCreateView(
      inflater: LayoutInflater,
      container: ViewGroup?,
      savedInstanceState: Bundle?
  ): View? {
      _binding = ResultProfileBinding.inflate(inflater, container, false)
      val view = binding.root
      return view
  }
  
  override fun onDestroyView() {
      super.onDestroyView()
      _binding = null
  }
  </code></pre>