fix: memory leak caused due to retained ViewInfoSheet instance in DesignerWorkspaceFragment

This commit is contained in:
Akash Yadav
2023-01-20 20:24:33 +05:30
parent 377e1d3827
commit 205a39b6bf
@@ -56,10 +56,13 @@ class DesignerWorkspaceFragment : BaseFragment() {
private var binding: FragmentDesignerWorkspaceBinding? = null
internal val viewModel by viewModels<WorkspaceViewModel>(ownerProducer = { requireActivity() })
private var _viewInfo: ViewInfoSheet? = null
private val touchSlop by lazy { get(requireContext()).scaledTouchSlop }
private val viewInfo by lazy { ViewInfoSheet() }
private val inflater by lazy { UiLayoutInflater() }
private val viewInfo: ViewInfoSheet
get() = this._viewInfo ?: ViewInfoSheet().also { _viewInfo = it }
internal var isInflating = false
internal val workspaceView by lazy {
UiViewGroup(LayoutFile(File(""), ""), LinearLayout::class.qualifiedName!!, binding!!.workspace)
@@ -136,13 +139,14 @@ class DesignerWorkspaceFragment : BaseFragment() {
override fun onDestroyView() {
super.onDestroyView()
this.binding = null
this._viewInfo = null
this.hierarchyHandler.release()
this.attrHandler.release()
this.inflationHandler.release()
this.inflater.close()
}
internal fun setupView(view: com.itsaky.androidide.inflater.IView) {
internal fun setupView(view: IView) {
if (view is CommonUiView && !view.needSetup) {
return
}
@@ -171,7 +175,7 @@ class DesignerWorkspaceFragment : BaseFragment() {
}
}
internal fun showViewInfo(view: com.itsaky.androidide.inflater.IView) {
internal fun showViewInfo(view: IView) {
viewModel.view = view
viewInfo.show(childFragmentManager, ViewInfoSheet.TAG)
}