Merge "Delay gargabe collection during onDestroy()" into sc-dev am: 3e84dd2783 am: 841a92e9dc

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/15178137

Change-Id: I5ce115f3a382c7d53cbf8168e1c39ad3eb978618
This commit is contained in:
Rubin Xu
2021-07-07 07:58:07 +00:00
committed by Automerger Merge Worker
2 changed files with 20 additions and 10 deletions

View File

@@ -18,6 +18,8 @@ package com.android.settings.password;
import android.app.KeyguardManager; import android.app.KeyguardManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.UserManager; import android.os.UserManager;
import android.util.Log; import android.util.Log;
import android.view.MenuItem; import android.view.MenuItem;
@@ -163,11 +165,14 @@ public abstract class ConfirmDeviceCredentialBaseActivity extends SettingsActivi
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
// Force a garbage collection immediately to remove remnant of user password shards // Force a garbage collection to remove remnant of user password shards from memory.
// from memory. // Execute this with a slight delay to allow the activity lifecycle to complete and
System.gc(); // the instance to become gc-able.
System.runFinalization(); new Handler(Looper.myLooper()).postDelayed(() -> {
System.gc(); System.gc();
System.runFinalization();
System.gc();
}, 5000);
} }
@Override @Override

View File

@@ -25,6 +25,8 @@ import android.graphics.Typeface;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.UserManager; import android.os.UserManager;
import android.os.storage.StorageManager; import android.os.storage.StorageManager;
@@ -216,11 +218,14 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
mPasswordEntry.setText(null); mPasswordEntry.setText(null);
// Force a garbage collection immediately to remove remnant of user password shards // Force a garbage collection to remove remnant of user password shards from memory.
// from memory. // Execute this with a slight delay to allow the activity lifecycle to complete and
System.gc(); // the instance to become gc-able.
System.runFinalization(); new Handler(Looper.myLooper()).postDelayed(() -> {
System.gc(); System.gc();
System.runFinalization();
System.gc();
}, 5000);
} }
private int getDefaultHeader() { private int getDefaultHeader() {