Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 765631a5 authored by Matt Pietal's avatar Matt Pietal
Browse files

Controls UI - Remove stale references to prevent memory leak

The binding controller uses callbacks to other areas of code to convey
subscriber changes. Since this area uses a binder, GC may not happen
immediately. Therefore, reassign callbacks when complete.

Fixes: 160305530
Test: external/perfetto/tools/java_heap_dump -n com.android.systemui
Change-Id: I6e4811dca8cb4eb5a3d75d5707bea611c5ce613b
parent 3dbb4873
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -49,6 +49,11 @@ open class ControlsBindingControllerImpl @Inject constructor(
        private const val SUGGESTED_STRUCTURES = 6L
        private const val SUGGESTED_CONTROLS_REQUEST =
            ControlsControllerImpl.SUGGESTED_CONTROLS_PER_STRUCTURE * SUGGESTED_STRUCTURES

        private val emptyCallback = object : ControlsBindingController.LoadCallback {
            override fun accept(controls: List<Control>) {}
            override fun error(message: String) {}
        }
    }

    private var currentUser = UserHandle.of(ActivityManager.getCurrentUser())
@@ -283,7 +288,7 @@ open class ControlsBindingControllerImpl @Inject constructor(
    }

    private inner class LoadSubscriber(
        val callback: ControlsBindingController.LoadCallback,
        var callback: ControlsBindingController.LoadCallback,
        val requestLimit: Long
    ) : IControlsSubscriber.Stub() {
        val loadedControls = ArrayList<Control>()
@@ -337,6 +342,10 @@ open class ControlsBindingControllerImpl @Inject constructor(
            if (isTerminated.get()) return

            _loadCancelInternal = {}

            // Reassign the callback to clear references to other areas of code. Binders such as
            // this may not be GC'd right away, so do not hold onto these references.
            callback = emptyCallback
            currentProvider?.cancelLoadTimeout()

            backgroundExecutor.execute {