Skip to content

Commit 5897591

Browse files
Johannes CarlssonJohan Redestig
authored andcommitted
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
1 parent 69ebb98 commit 5897591

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

services/java/com/android/server/am/ActivityManagerService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11035,6 +11035,9 @@ private final void processNextBroadcast(boolean fromMsg) {
1103511035
performReceiveLocked(r.callerApp, r.resultTo,
1103611036
new Intent(r.intent), r.resultCode,
1103711037
r.resultData, r.resultExtras, false, false);
11038+
// Set this to null so that the reference
11039+
// (local and remote) isnt kept in the mBroadcastHistory.
11040+
r.resultTo = null;
1103811041
} catch (RemoteException e) {
1103911042
Slog.w(TAG, "Failure sending broadcast result of " + r.intent, e);
1104011043
}

services/java/com/android/server/am/BroadcastRecord.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class BroadcastRecord extends Binder {
4545
final boolean initialSticky; // initial broadcast from register to sticky?
4646
final String requiredPermission; // a permission the caller has required
4747
final List receivers; // contains BroadcastFilter and ResolveInfo
48-
final IIntentReceiver resultTo; // who receives final result if non-null
48+
IIntentReceiver resultTo; // who receives final result if non-null
4949
long dispatchTime; // when dispatch started on this set of receivers
5050
long receiverTime; // when current receiver started for timeouts.
5151
long finishTime; // when we finished the broadcast.

0 commit comments

Comments
 (0)