当前位置:网站首页>Cause of handler memory leak
Cause of handler memory leak
2022-07-07 00:59:00 【yinianzhijian99】
Cause of memory leak : When an object is no longer used , It should be recycled but because another object in use holds its reference , As a result, it cannot be recycled .
Solution 1: stay Java in , Non static inner classes or anonymous inner classes hold references to external classes by default , Use Handler when , Need to Handler Objects are declared as static variables or use weak references . When Handler The internal message queue has not been processed ( Or delay the processing of messages ), Don't hold external references , It does not affect the logoff recycling of external objects .
Solution 2: When an external class object ends its life cycle , Empty Handler Inside the message queue . For example Activity Of onDestroy() Method to empty the message queue :
@Override
protected void onDestroy() {
super.onDestroy();
// External class Activity At the end of the life cycle , Empty message queue , end Handler Life cycle
mHandler.removeCallbacksAndMessages(null);
mHandler = null;
}边栏推荐
- Activereportsjs 3.1 Chinese version | | | activereportsjs 3.1 English version
- Leetcode (547) - number of provinces
- 集合(泛型 & List & Set & 自定义排序)
- Interface (interface related meaning, different abstract classes, interface callback)
- A brief history of deep learning (II)
- Advantages and disadvantages of code cloning
- 【批处理DOS-CMD命令-汇总和小结】-跳转、循环、条件命令(goto、errorlevel、if、for[读取、切分、提取字符串]、)cmd命令错误汇总,cmd错误
- Equals() and hashcode()
- Use mujoco to simulate Cassie robot
- Chenglian premium products has completed the first step to enter the international capital market by taking shares in halber international
猜你喜欢

Attention SLAM:一種從人類注意中學習的視覺單目SLAM

Deep understanding of distributed cache design

Basic information of mujoco

Memory optimization of Amazon memorydb for redis and Amazon elasticache for redis

Dell Notebook Periodic Flash Screen Fault

5种不同的代码相似性检测,以及代码相似性检测的发展趋势

深度学习之环境配置 jupyter notebook

Configuring the stub area of OSPF for Huawei devices

Stm32f407 ------- DAC digital to analog conversion
![[C language] dynamic address book](/img/e7/ca1030a1099fe1f59f5d8dd722fdb7.jpg)
[C language] dynamic address book
随机推荐
Slow database query optimization
Lombok 同时使⽤ @Data 和 @Builder 的坑,你中招没?
5种不同的代码相似性检测,以及代码相似性检测的发展趋势
Alexnet experiment encounters: loss Nan, train ACC 0.100, test ACC 0.100
批量获取中国所有行政区域经边界纬度坐标(到县区级别)
【批处理DOS-CMD命令-汇总和小结】-字符串搜索、查找、筛选命令(find、findstr),Find和findstr的区别和辨析
View remote test data and records anytime, anywhere -- ipehub2 and ipemotion app
Configuring the stub area of OSPF for Huawei devices
ZABBIX 5.0: automatically monitor Alibaba cloud RDS through LLD
[Niuke classic question 01] bit operation
[C language] dynamic address book
Attention slam: a visual monocular slam that learns from human attention
Levels - UE5中的暴雨效果
【批处理DOS-CMD命令-汇总和小结】-查看或修改文件属性(ATTRIB),查看、修改文件关联类型(assoc、ftype)
【JokerのZYNQ7020】AXI_EMC。
stm32F407-------SPI通信
Five different code similarity detection and the development trend of code similarity detection
Advanced learning of MySQL -- basics -- multi table query -- external connection
【JVM调优实战100例】05——方法区调优实战(下)
build. How to configure the dependent version number in the gradle file