OSDN Git Service

Fix PremiumSmsAccess memory leak
authordaqi <daqi@xiaomi.com>
Sat, 17 Jun 2017 07:24:44 +0000 (15:24 +0800)
committerdaqi <daqi@xiaomi.com>
Fri, 23 Jun 2017 06:17:49 +0000 (14:17 +0800)
[Cause of Defect]
PremiumSmsAccess forget to invoke Session and AppStateSmsPremBridge
release method in the onDestroy callback.
And that would lead to the leak of activity context.

Test: 1. Settings - Apps - Advanced - Special access - Premium SMS access
      2. adb shell dumpsys meminfo com.android.settings
      3. observe activity object number
      4. back to the last page
      5. use AS trigger Settings gc several times
      6. adb shell dumpsys meminfo com.android.settings
      7. observe activity object number to check if the activity number decrease

Change-Id: I359900c16fa866fba94d187a61cf6bebbdd1ed0b
Signed-off-by: daqi <daqi@xiaomi.com>
src/com/android/settings/applications/PremiumSmsAccess.java

index c4bb1a8..1bc561b 100644 (file)
@@ -76,6 +76,13 @@ public class PremiumSmsAccess extends EmptyTextSettings implements Callback, Cal
     }
 
     @Override
+    public void onDestroy() {
+        mSmsBackend.release();
+        mSession.release();
+        super.onDestroy();
+    }
+
+    @Override
     protected int getMetricsCategory() {
         return MetricsProto.MetricsEvent.PREMIUM_SMS_ACCESS;
     }