一次百度内存泄漏定位
来源:互联网 发布:物流管理信息系统软件 编辑:程序博客网 时间:2024/05/19 17:04
封装百度定位类BDLocationManager单例类,封装了一些启动定位,停止定位、注册监听、注销监听等的方法。大概代码是这样。
public class BDLocationManager{ private static BDLocationManager INSTANCE = null; private BDLocationListener lastListener; public synchronized static void init(Context context) { if (INSTANCE == null) { INSTANCE = new BDLocationManager(context.getApplicationContext()); } } public synchronized static BDLocationManager getInstance() { return INSTANCE; } public void registerLocationListener(BDLocationListener listener) { unRegisterLocationListener(lastListener); if (locationClient != null && listener != null) { locationClient.registerLocationListener(listener); lastListener = listener; } } public void unRegisterLocationListener(BDLocationListener listener) { if (locationClient != null && listener != null) { locationClient.unRegisterLocationListener(listener); } } public void stop() { unRegisterLocationListener(lastListener); lastListener = null; if (locationClient != null && locationClient.isStarted()) { locationClient.stop(); } }}使用BDLocationManager.getInstance().registerLocationListener()注册,回调定位结果。定位完成后调用stop()停止定位,停止定位注销了 unRegisterLocationListener(),BDLocationManager全局有效对lastListener 有引用,没有对lastListener 进行释放,导致调用定位的类没有被完全回收,造成内存泄漏。
阅读全文
0 0
- 一次百度内存泄漏定位
- 【定位分享】记一次内存泄漏定位
- 一次内存泄漏问题定位过程与分析
- 记录一次kernel内存泄漏的查找定位过程
- 内存泄漏定位
- VC++内存泄漏定位
- 内存泄漏定位
- 定位内存泄漏位置
- 内存泄漏定位
- 内存泄漏定位
- 内存泄漏定位
- VC++内存泄漏定位
- VC++内存泄漏定位
- VC++内存泄漏定位
- VC++内存泄漏定位
- vc++内存泄漏定位
- 内存泄漏定位
- VC++内存泄漏定位
- ncre三级信息安全 考试感悟(上)
- 1-Azkaban用户登录篇
- File***could only be replicated to 0 nodes instead of minReplication (=1)
- 不同软件中的数据类型
- 学习回顾mysql常用函数(1)
- 一次百度内存泄漏定位
- 在centOS上安装Node
- Fiddler抓取手机端APP接口数据
- Oracle分页的实现方式
- Redis学习-2:Linux安装Redis
- 从JDK源码看InputStream
- (三)JAVA菜鸟养成记--抽象类和接口
- nginx安装 打开php文件自动下载的问题
- java使用反射将json对象转换为java对象