diff options
| author | 2010-10-27 10:08:10 +0200 | |
|---|---|---|
| committer | 2011-01-05 18:59:07 -0800 | |
| commit | b5a8654dea9ea8443b41f8ff3668ae4074e13a07 (patch) | |
| tree | cb4073d122303f155263187e68bc3d281694460c | |
| parent | c91f9fe542fd1ca9d6da432faeba60d35c4d5c49 (diff) | |
Clear reference to the IIntentReceiver in order to avoid memory leak
When using sendOrderedBroadcast(..) with a BroadcastReceiver the
BroadcastReceiver instance was not released. The reason for this was that
the resultTo field in the BroadcastRecord kept a reference until it was pushed
out of the mBroadcastHistory. This reference in turn kept a reference to the
process side IIntentReceiver (implemented in ReceiverDispatcher$InnerReceiver).
This in turn had a strong reference (through mStrongRef) to the Context.
In order to keep the debug output the resultTo is also kept as a String in the
new resultToString variable.
Change-Id: I4382a22a541c27b3694fb2b78a04ee820b235f8f
| -rw-r--r-- | services/java/com/android/server/am/ActivityManagerService.java | 3 | ||||
| -rw-r--r-- | services/java/com/android/server/am/BroadcastRecord.java | 2 |
2 files changed, 4 insertions, 1 deletions
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java index 08e22ed167fc..478102082f25 100644 --- a/services/java/com/android/server/am/ActivityManagerService.java +++ b/services/java/com/android/server/am/ActivityManagerService.java @@ -11009,6 +11009,9 @@ public final class ActivityManagerService extends ActivityManagerNative performReceiveLocked(r.callerApp, r.resultTo, new Intent(r.intent), r.resultCode, r.resultData, r.resultExtras, false, false); + // Set this to null so that the reference + // (local and remote) isnt kept in the mBroadcastHistory. + r.resultTo = null; } catch (RemoteException e) { Slog.w(TAG, "Failure sending broadcast result of " + r.intent, e); } diff --git a/services/java/com/android/server/am/BroadcastRecord.java b/services/java/com/android/server/am/BroadcastRecord.java index b268efa18c6f..c95053e0b84e 100644 --- a/services/java/com/android/server/am/BroadcastRecord.java +++ b/services/java/com/android/server/am/BroadcastRecord.java @@ -45,7 +45,7 @@ class BroadcastRecord extends Binder { final boolean initialSticky; // initial broadcast from register to sticky? final String requiredPermission; // a permission the caller has required final List receivers; // contains BroadcastFilter and ResolveInfo - final IIntentReceiver resultTo; // who receives final result if non-null + IIntentReceiver resultTo; // who receives final result if non-null long dispatchTime; // when dispatch started on this set of receivers long receiverTime; // when current receiver started for timeouts. long finishTime; // when we finished the broadcast. |