From 08eae598a8c46291bae58dc0bff7d8ee1637a844 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Fri, 26 Aug 2022 15:47:19 +0800 Subject: [PATCH] Unlink death recipient which references to DisplayContent Though the remote side (SystemUI) will unregister the recipient when receiving display removed, it may be too late that the DisplayContent is removed from RootWindowContainer, then WMS# setDisplayWindowInsetsController becomes no-op and causes the instance of DisplayContent to be leaked. Also release windowing layer manually in case it is an additional layer which isn't managed by WindowContainer (e.g. if the display does not have FEATURE_WINDOWED_MAGNIFICATION). So it won't rely on GC to release. Bug: 240704591 Test: Create/destroy virtual display many times. GC: adb shell 'kill -10 `pidof system_server`' No surface of virtual display exists in: adb shell dumpsys SurfaceFlinger grep -A 100 'Offscreen' Change-Id: Iac84992b8eb13c4348dfca87924fb0c2fa94a5b8 --- services/core/java/com/android/server/wm/DisplayContent.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 5ac8bd7d89c43..09e5cc6ef4464 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -3176,8 +3176,12 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this); mPointerEventDispatcher.dispose(); setRotationAnimation(null); + // Unlink death from remote to clear the reference from binder -> mRemoteInsetsDeath + // -> this DisplayContent. + setRemoteInsetsController(null); mWmService.mAnimator.removeDisplayLocked(mDisplayId); mOverlayLayer.release(); + mWindowingLayer.release(); mInputMonitor.onDisplayRemoved(); mWmService.mDisplayNotificationController.dispatchDisplayRemoved(this); mWmService.mAccessibilityController.onDisplayRemoved(mDisplayId);