diff --git a/bindables/src/main/java/com/skydoves/bindables/BindingActivity.kt b/bindables/src/main/java/com/skydoves/bindables/BindingActivity.kt index 1fff93d..6a3c945 100644 --- a/bindables/src/main/java/com/skydoves/bindables/BindingActivity.kt +++ b/bindables/src/main/java/com/skydoves/bindables/BindingActivity.kt @@ -67,4 +67,13 @@ abstract class BindingActivity constructor( binding.notifyChange() } } + + /** + * Removes binding listeners to expression variables and destroys the [binding] backing property for preventing + * leaking the [ViewDataBinding] that references the Context. + */ + override fun onDestroy() { + super.onDestroy() + binding.unbind() + } } diff --git a/bindables/src/main/java/com/skydoves/bindables/BindingBottomSheetDialogFragment.kt b/bindables/src/main/java/com/skydoves/bindables/BindingBottomSheetDialogFragment.kt index 871f760..a75762a 100644 --- a/bindables/src/main/java/com/skydoves/bindables/BindingBottomSheetDialogFragment.kt +++ b/bindables/src/main/java/com/skydoves/bindables/BindingBottomSheetDialogFragment.kt @@ -86,6 +86,7 @@ abstract class BindingBottomSheetDialogFragment constructor */ override fun onDestroyView() { super.onDestroyView() + _binding?.unbind() _binding = null } } diff --git a/bindables/src/main/java/com/skydoves/bindables/BindingComponentActivity.kt b/bindables/src/main/java/com/skydoves/bindables/BindingComponentActivity.kt index 42a544a..9e42a97 100644 --- a/bindables/src/main/java/com/skydoves/bindables/BindingComponentActivity.kt +++ b/bindables/src/main/java/com/skydoves/bindables/BindingComponentActivity.kt @@ -67,4 +67,13 @@ abstract class BindingComponentActivity constructor( binding.notifyChange() } } + + /** + * Removes binding listeners to expression variables and destroys the [binding] backing property for preventing + * leaking the [ViewDataBinding] that references the Context. + */ + override fun onDestroy() { + super.onDestroy() + binding.unbind() + } } diff --git a/bindables/src/main/java/com/skydoves/bindables/BindingDialogFragment.kt b/bindables/src/main/java/com/skydoves/bindables/BindingDialogFragment.kt index 73e19f7..84e1610 100644 --- a/bindables/src/main/java/com/skydoves/bindables/BindingDialogFragment.kt +++ b/bindables/src/main/java/com/skydoves/bindables/BindingDialogFragment.kt @@ -86,6 +86,7 @@ abstract class BindingDialogFragment constructor( */ override fun onDestroyView() { super.onDestroyView() + _binding?.unbind() _binding = null } } diff --git a/bindables/src/main/java/com/skydoves/bindables/BindingFragment.kt b/bindables/src/main/java/com/skydoves/bindables/BindingFragment.kt index f3c75a4..8c1a155 100644 --- a/bindables/src/main/java/com/skydoves/bindables/BindingFragment.kt +++ b/bindables/src/main/java/com/skydoves/bindables/BindingFragment.kt @@ -86,6 +86,7 @@ abstract class BindingFragment constructor( */ override fun onDestroyView() { super.onDestroyView() + _binding?.unbind() _binding = null } } diff --git a/bindables/src/main/java/com/skydoves/bindables/BindingFragmentActivity.kt b/bindables/src/main/java/com/skydoves/bindables/BindingFragmentActivity.kt index 5d5e6bf..2dde844 100644 --- a/bindables/src/main/java/com/skydoves/bindables/BindingFragmentActivity.kt +++ b/bindables/src/main/java/com/skydoves/bindables/BindingFragmentActivity.kt @@ -67,4 +67,13 @@ abstract class BindingFragmentActivity constructor( binding.notifyChange() } } + + /** + * Removes binding listeners to expression variables and destroys the [binding] backing property for preventing + * leaking the [ViewDataBinding] that references the Context. + */ + override fun onDestroy() { + super.onDestroy() + binding.unbind() + } } diff --git a/bindables/src/main/java/com/skydoves/bindables/BindingModel.kt b/bindables/src/main/java/com/skydoves/bindables/BindingModel.kt index 76c7100..74a0bd1 100644 --- a/bindables/src/main/java/com/skydoves/bindables/BindingModel.kt +++ b/bindables/src/main/java/com/skydoves/bindables/BindingModel.kt @@ -112,4 +112,14 @@ abstract class BindingModel : BindingObservable { propertyCallbacks.notifyCallbacks(this, BR._all, null) } } + + /** + * Clears all binding properties from the callback registry. + */ + override fun clearAllProperties() { + synchronized(lock) lock@{ + val propertyCallbacks = propertyCallbacks ?: return@lock + propertyCallbacks.clear() + } + } }