当前位置:网站首页>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;
}
边栏推荐
- Web project com mysql. cj. jdbc. Driver and com mysql. jdbc. Driver differences
- Configuring OSPF basic functions for Huawei devices
- Building a dream in the digital era, the Xi'an station of the city chain science and Technology Strategy Summit ended smoothly
- A brief history of deep learning (I)
- 省市区三级坐标边界数据csv转JSON
- Periodic flash screen failure of Dell notebook
- 批量获取中国所有行政区域经边界纬度坐标(到县区级别)
- 腾讯云 WebShell 体验
- 深度学习框架TF安装
- pyflink的安装和测试
猜你喜欢
[牛客] [NOIP2015]跳石头
【YoloV5 6.0|6.1 部署 TensorRT到torchserve】环境搭建|模型转换|engine模型部署(详细的packet文件编写方法)
筑梦数字时代,城链科技战略峰会西安站顺利落幕
[Batch dos - cmd Command - Summary and Summary] - String search, find, Filter Commands (FIND, findstr), differentiation and Analysis of Find and findstr
[software reverse automation] complete collection of reverse tools
【批处理DOS-CMD命令-汇总和小结】-字符串搜索、查找、筛选命令(find、findstr),Find和findstr的区别和辨析
Alexnet experiment encounters: loss Nan, train ACC 0.100, test ACC 0.100
批量获取中国所有行政区域经边界纬度坐标(到县区级别)
重上吹麻滩——段芝堂创始人翟立冬游记
[C language] dynamic address book
随机推荐
第六篇,STM32脉冲宽度调制(PWM)编程
Return to blowing marshland -- travel notes of zhailidong, founder of duanzhitang
重上吹麻滩——段芝堂创始人翟立冬游记
Deep understanding of distributed cache design
alexnet实验偶遇:loss nan, train acc 0.100, test acc 0.100情况
Batch obtain the latitude coordinates of all administrative regions in China (to the county level)
批量获取中国所有行政区域经边界纬度坐标(到县区级别)
Installation and testing of pyflink
A brief history of deep learning (II)
第七篇,STM32串口通信编程
Summary of being a microservice R & D Engineer in the past year
stm32F407-------SPI通信
Advanced learning of MySQL -- basics -- multi table query -- joint query
Leetcode(547)——省份数量
tensorflow 1.14指定gpu运行设置
Attention slam: a visual monocular slam that learns from human attention
通过串口实现printf函数,中断实现串口数据接收
Slow database query optimization
Mujoco produces analog video
「精致店主理人」青年创业孵化营·首期顺德场圆满结束!