Skip to content

Commit fce8132

Browse files
authored
Merge pull request #6 from bayu07750/development/delta
set binding to null prevent memory leak
2 parents ffc6f85 + 85fdbf8 commit fce8132

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

core/src/main/java/com/crocodic/core/base/fragment/CoreFragment.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,29 @@ import androidx.fragment.app.Fragment
1111
import com.crocodic.core.helper.ImagePreviewHelper
1212
import com.crocodic.core.helper.util.ClickPrevention
1313

14-
abstract class CoreFragment<VB : ViewDataBinding>(@LayoutRes private val layoutRes: Int): Fragment(), ClickPrevention {
14+
abstract class CoreFragment<VB : ViewDataBinding>(@LayoutRes private val layoutRes: Int) :
15+
Fragment(), ClickPrevention {
1516

16-
protected lateinit var binding: VB
17+
private var _binding: VB? = null
18+
protected val binding get() = _binding!!
1719

1820
open var title: String = ""
1921
open var hasLoadedOnce = false
2022

2123
val imagePreview by lazy { context?.let { ImagePreviewHelper(it) } }
2224

23-
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
24-
binding = DataBindingUtil.inflate(inflater, layoutRes, container, false)
25+
override fun onCreateView(
26+
inflater: LayoutInflater,
27+
container: ViewGroup?,
28+
savedInstanceState: Bundle?
29+
): View? {
30+
_binding = DataBindingUtil.inflate(inflater, layoutRes, container, false)
2531
binding.lifecycleOwner = this
2632
return binding.root
2733
}
34+
35+
override fun onDestroyView() {
36+
super.onDestroyView()
37+
_binding = null
38+
}
2839
}

0 commit comments

Comments
 (0)