本地管理广播接收器泄露? [英] Locally managed broadcast receiver leak?

查看:246
本文介绍了本地管理广播接收器泄露?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可能是本地(即与LocalBroadcastManager管理)的BroadcastReceiver泄漏当应用程序被系统杀死?

Is it possible that a local (i.e. managed with LocalBroadcastManager) BroadcastReceiver leaks when the app is killed by the system?

具体使用情况下,我需要它,我想注册/注销的BroadcastReceiver在活动的onCreate /的onDestroy(我需要的接收器被激活时,该活动是不可见的),但我不喜欢冒险做这个导致内存泄漏。据我了解,如果一个活动是由系统破坏,运行的onDestroy和接收器的注册。如果有什么应用程序被杀害?是否仍然接收器周围,或者是本地的,它得到与应用程序一起杀?

The specific use case for which I need it is that I would like to register/unregister the BroadcastReceiver in an Activity's onCreate/onDestroy (I need the receiver to be active when the activity is not visible), but I wouldn't like to risk causing a memory leak by doing this. As I understand, if a single activity is destroyed by the system, onDestroy runs and the receiver is unregistered. What if the app is killed? Does the receiver remain around, or, being local, does it get killed along with the app?

推荐答案

如果你偷看里面的<一个href="https://android.googlesource.com/platform/frameworks/support/+/refs/heads/master/v4/java/android/support/v4/content/LocalBroadcastManager.java"相对=nofollow> LocalBroadcastManager 源$ C ​​$ C ,你会看到它实际上只是一个普通的类(本地如你所说)与地图连接的BroadcastReceiver 与各相应的列表 的IntentFilter

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.

没有被记录在系统级,因此否:如果应用程序被杀害,LocalBroadcastManager类打死它,不会发生泄漏

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.

这篇关于本地管理广播接收器泄露?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆