Skip to content Skip to sidebar Skip to footer

Locally Managed Broadcast Receiver Leak?

Is it possible that a local (i.e. managed with LocalBroadcastManager) BroadcastReceiver leaks when the app is killed by the system? The specific use case for which I need it is tha

Solution 1:

If you peek inside LocalBroadcastManager source code, you'll see it's really just a normal class ("local" as you said) with a Map connecting the various BroadcastReceiver with the corresponding List of IntentFilter.

Nothing is registered at the "system level" so NO: if the app is killed, LocalBroadcastManager class is killed with it and no leak will occur.

Solution 2:

You should absolutely unregister it in onDestroy because onDestroy doesn't mean your app is finished- just your Activity. Other Activities in your app could still be running, so that receiver would cause a leak.

Post a Comment for "Locally Managed Broadcast Receiver Leak?"