4. Registion的泄漏问题
这里的Registion主要有两种,分别是Service、BroadCastReceiver:
4.2 检测时机
这里先补充一个前置知识点,stopService的流程:
Context.stopSerivce -> ActivityThread.STOP_SERVICE -> ActivityThread.scheduleContextCleanup() -> LoadApk.removeContextRegistrations
我们需要的检测时机,在removeContextRegistrations,这里面用到了两个成员变量:
//根据context,来存储当前的广播以及广播分发器
private final ArrayMap<Context, ArrayMap<BroadcastReceiver, ReceiverDispatcher>> mReceivers
= new ArrayMap<>();
//根据context,来存储service以及service的分发器
private final ArrayMap<Context, ArrayMap<ServiceConnection, LoadedApk.ServiceDispatcher>> mServices
= new ArrayMap<>();
public void removeContextRegistrations(Context context,
String who, String what

本文详细探讨了Android ActivityThread在Context.stopService过程中如何检测Service和BroadcastReceiver的泄漏,并通过mReceivers和mServices成员变量进行清理。重点介绍了如何在removeContextRegistrations方法中分析并报告接收器和服务连接的泄漏情况,以及StrictMode在检测中的角色。
最低0.47元/天 解锁文章
3954

被折叠的 条评论
为什么被折叠?



