当前位置:网站首页>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;
}边栏推荐
- Use mujoco to simulate Cassie robot
- stm32F407-------DAC数模转换
- Periodic flash screen failure of Dell notebook
- Tencent cloud webshell experience
- Learn to use code to generate beautiful interface documents!!!
- 深度学习之环境配置 jupyter notebook
- 深度学习框架TF安装
- Data processing of deep learning
- A brief history of deep learning (II)
- Stm32f407 ------- SPI communication
猜你喜欢

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

Threejs image deformation enlarge full screen animation JS special effect
![[force buckle]41 Missing first positive number](/img/2e/6a0d3ea9264798f67be1ec1c81ca9e.jpg)
[force buckle]41 Missing first positive number

学习光线跟踪一样的自3D表征Ego3RT

Data sharing of the 835 postgraduate entrance examination of software engineering in Hainan University in 23

Periodic flash screen failure of Dell notebook

C9 colleges and universities, doctoral students make a statement of nature!

.class文件的字节码结构

Hero League | King | cross the line of fire BGM AI score competition sharing

windows安装mysql8(5分钟)
随机推荐
A brief history of deep learning (II)
【JokerのZYNQ7020】AXI_EMC。
alexnet实验偶遇:loss nan, train acc 0.100, test acc 0.100情况
paddlehub应用出现paddle包报错的问题
腾讯云 WebShell 体验
批量获取中国所有行政区域经边界纬度坐标(到县区级别)
Advanced learning of MySQL -- Fundamentals -- four characteristics of transactions
Let's talk about 15 data source websites I often use
Configuring OSPF basic functions for Huawei devices
Periodic flash screen failure of Dell notebook
[software reverse - solve flag] memory acquisition, inverse transformation operation, linear transformation, constraint solving
Article management system based on SSM framework
[user defined type] structure, union, enumeration
Slow database query optimization
Meet the level 3 requirements of ISO 2.0 with the level B construction standard of computer room | hybrid cloud infrastructure
Attention SLAM:一种从人类注意中学习的视觉单目SLAM
Advanced learning of MySQL -- basics -- multi table query -- inner join
代码克隆的优缺点
mongodb客户端操作(MongoRepository)
城联优品入股浩柏国际进军国际资本市场,已完成第一步