diff options
| author | 2024-10-03 22:50:47 +0000 | |
|---|---|---|
| committer | 2024-10-03 22:50:47 +0000 | |
| commit | 1b2bca67c50741cb560f491c24764573ac5f2625 (patch) | |
| tree | 045077d2b7f619836e8eb1ee228e8f1a1e45c5d0 | |
| parent | 53aebb03325b85ddaeb76ff3e71593b2097e8274 (diff) | |
Optimize the removal of garbage collected references to avoid memory leaks
mAllResourceReferences collects weak references to a resource when it is constructed, which is used to update the resource path of the library when loading webview. Currently, its garbage collected references(mAllResourceReferencesQueue) only cleaned up when ResourcesManager#redirectAllResourcesToNewImplLocked is executed, which means that if the application does not rely on webview, then cleanup cannot be performed.
Therefore, we need to clean up the mAllResourceReferencesQueue once when creating a new Resource and preparing to add its weak reference to mAllResourceReferences.
Bug: 363887630
Test: Create multiple new resources in app and observe mAllResourceReferencesQueue
Signed-off-by: zhangshuai10 <zhangshuai10@xiaomi.corp-partner.google.com>
(cherry picked from https://partner-android-review.googlesource.com/q/commit:d64e23dcff6acee2b8dd57a047389172fe95054e)
Merged-In: Ide10752f2dce86ff9b7d16335e625ae1919255f3
Change-Id: Ide10752f2dce86ff9b7d16335e625ae1919255f3
| -rw-r--r-- | core/java/android/app/ResourcesManager.java | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/core/java/android/app/ResourcesManager.java b/core/java/android/app/ResourcesManager.java index 84a4eb4acddc..dbfe2eeabdc7 100644 --- a/core/java/android/app/ResourcesManager.java +++ b/core/java/android/app/ResourcesManager.java @@ -1977,6 +1977,7 @@ public class ResourcesManager { public void registerAllResourcesReference(@NonNull Resources resources) { if (android.content.res.Flags.registerResourcePaths()) { synchronized (mLock) { + cleanupReferences(mAllResourceReferences, mAllResourceReferencesQueue); mAllResourceReferences.add( new WeakReference<>(resources, mAllResourceReferencesQueue)); } |