1
0
Fork 0

No issue: Fix LeakCanary detected memory leaks

Co-authored-by: Emily Kager <emilykager@gmail.com>
Co-authored-by: Pierre-Yves Ricau <py@squareup.com>
master
ekager 2020-02-20 18:51:12 -08:00 committed by Jeff Boek
parent bd4701f29e
commit a6b07afa95
2 changed files with 25 additions and 8 deletions

View File

@ -98,8 +98,14 @@ import org.mozilla.fenix.theme.ThemeManager
@Suppress("TooManyFunctions", "LargeClass") @Suppress("TooManyFunctions", "LargeClass")
abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, SessionManager.Observer { abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, SessionManager.Observer {
protected lateinit var browserFragmentStore: BrowserFragmentStore protected lateinit var browserFragmentStore: BrowserFragmentStore
protected lateinit var browserInteractor: BrowserToolbarViewInteractor
protected lateinit var browserToolbarView: BrowserToolbarView private var _browserInteractor: BrowserToolbarViewInteractor? = null
protected val browserInteractor: BrowserToolbarViewInteractor
get() = _browserInteractor!!
private var _browserToolbarView: BrowserToolbarView? = null
protected val browserToolbarView: BrowserToolbarView
get() = _browserToolbarView!!
protected val readerViewFeature = ViewBoundFeatureWrapper<ReaderViewFeature>() protected val readerViewFeature = ViewBoundFeatureWrapper<ReaderViewFeature>()
@ -191,15 +197,16 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
topSiteStorage = requireComponents.core.topSiteStorage topSiteStorage = requireComponents.core.topSiteStorage
) )
browserInteractor = BrowserInteractor( _browserInteractor = BrowserInteractor(
browserToolbarController = browserToolbarController browserToolbarController = browserToolbarController
) )
browserToolbarView = BrowserToolbarView( _browserToolbarView = BrowserToolbarView(
container = view.browserLayout, container = view.browserLayout,
shouldUseBottomToolbar = context.settings().shouldUseBottomToolbar, shouldUseBottomToolbar = context.settings().shouldUseBottomToolbar,
interactor = browserInteractor, interactor = browserInteractor,
customTabSession = customTabSessionId?.let { sessionManager.findSessionById(it) } customTabSession = customTabSessionId?.let { sessionManager.findSessionById(it) },
lifecycleOwner = this.viewLifecycleOwner
) )
toolbarIntegration.set( toolbarIntegration.set(
@ -764,6 +771,15 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
} }
} }
/*
* Dereference these views when the fragment view is destroyed to prevent memory leaks
*/
override fun onDestroyView() {
super.onDestroyView()
_browserToolbarView = null
_browserInteractor = null
}
companion object { companion object {
private const val KEY_CUSTOM_TAB_SESSION_ID = "custom_tab_session_id" private const val KEY_CUSTOM_TAB_SESSION_ID = "custom_tab_session_id"
private const val REQUEST_CODE_DOWNLOAD_PERMISSIONS = 1 private const val REQUEST_CODE_DOWNLOAD_PERMISSIONS = 1

View File

@ -11,9 +11,9 @@ import android.view.ViewGroup
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.PopupWindow import android.widget.PopupWindow
import androidx.annotation.LayoutRes import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.lifecycle.LifecycleOwner
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import kotlinx.android.extensions.LayoutContainer import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.browser_toolbar_popup_window.view.* import kotlinx.android.synthetic.main.browser_toolbar_popup_window.view.*
@ -45,7 +45,8 @@ class BrowserToolbarView(
private val container: ViewGroup, private val container: ViewGroup,
private val shouldUseBottomToolbar: Boolean, private val shouldUseBottomToolbar: Boolean,
private val interactor: BrowserToolbarViewInteractor, private val interactor: BrowserToolbarViewInteractor,
private val customTabSession: Session? private val customTabSession: Session?,
private val lifecycleOwner: LifecycleOwner
) : LayoutContainer { ) : LayoutContainer {
override val containerView: View? override val containerView: View?
@ -188,7 +189,7 @@ class BrowserToolbarView(
hasAccountProblem = components.backgroundServices.accountManager.accountNeedsReauth(), hasAccountProblem = components.backgroundServices.accountManager.accountNeedsReauth(),
shouldReverseItems = !shouldUseBottomToolbar, shouldReverseItems = !shouldUseBottomToolbar,
onItemTapped = { interactor.onBrowserToolbarMenuItemTapped(it) }, onItemTapped = { interactor.onBrowserToolbarMenuItemTapped(it) },
lifecycleOwner = container.context as AppCompatActivity, lifecycleOwner = lifecycleOwner,
sessionManager = sessionManager, sessionManager = sessionManager,
bookmarksStorage = bookmarkStorage bookmarksStorage = bookmarkStorage
) )