当前位置:网站首页>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;
}边栏推荐
- Js+svg love diffusion animation JS special effects
- Advanced learning of MySQL -- basics -- basic operation of transactions
- Meet the level 3 requirements of ISO 2.0 with the level B construction standard of computer room | hybrid cloud infrastructure
- Advanced learning of MySQL -- basics -- multi table query -- self join
- Model-Free Control
- 【JVM调优实战100例】04——方法区调优实战(上)
- Mongodb client operation (mongorepository)
- Configuring OSPF basic functions for Huawei devices
- 省市区三级坐标边界数据csv转JSON
- [C language] dynamic address book
猜你喜欢

C9高校,博士生一作发Nature!

Part IV: STM32 interrupt control programming

How to judge whether an element in an array contains all attribute values of an object

JS+SVG爱心扩散动画js特效

Periodic flash screen failure of Dell notebook

Stm32f407 ------- DAC digital to analog conversion

【软件逆向-自动化】逆向工具大全
![Explain in detail the matrix normalization function normalize() of OpenCV [norm or value range of the scoped matrix (normalization)], and attach norm_ Example code in the case of minmax](/img/87/3fee9e6f687b0c3efe7208a25f07f1.png)
Explain in detail the matrix normalization function normalize() of OpenCV [norm or value range of the scoped matrix (normalization)], and attach norm_ Example code in the case of minmax

Activereportsjs 3.1 Chinese version | | | activereportsjs 3.1 English version

集合(泛型 & List & Set & 自定义排序)
随机推荐
dynamic programming
【批處理DOS-CMD命令-匯總和小結】-字符串搜索、查找、篩選命令(find、findstr),Find和findstr的區別和辨析
What kind of experience is it to realize real-time collaboration in jupyter
用tkinter做一个简单图形界面
Mujoco finite state machine and trajectory tracking
Learning notes 5: ram and ROM
Markov decision process
【软件逆向-自动化】逆向工具大全
tensorflow 1.14指定gpu运行设置
【批处理DOS-CMD命令-汇总和小结】-查看或修改文件属性(ATTRIB),查看、修改文件关联类型(assoc、ftype)
A brief history of deep learning (II)
Notes of training courses selected by Massey school
String comparison in batch file - string comparison in batch file
.class文件的字节码结构
Advanced learning of MySQL -- basics -- transactions
The printf function is realized through the serial port, and the serial port data reception is realized by interrupt
[牛客] B-完全平方数
Advanced learning of MySQL -- Fundamentals -- four characteristics of transactions
【批处理DOS-CMD命令-汇总和小结】-跳转、循环、条件命令(goto、errorlevel、if、for[读取、切分、提取字符串]、)cmd命令错误汇总,cmd错误
迈动互联中标北京人寿保险,助推客户提升品牌价值