当前位置:网站首页>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;
}
边栏推荐
- 【软件逆向-求解flag】内存获取、逆变换操作、线性变换、约束求解
- Trace tool for MySQL further implementation plan
- 深度学习之线性代数
- Matlab learning notes
- Learn to use code to generate beautiful interface documents!!!
- Chapter II proxy and cookies of urllib Library
- Learning notes 5: ram and ROM
- Part V: STM32 system timer and general timer programming
- Lombok 同时使⽤ @Data 和 @Builder 的坑,你中招没?
- [Batch dos - cmd Command - Summary and Summary] - String search, find, Filter Commands (FIND, findstr), differentiation and Analysis of Find and findstr
猜你喜欢
.class文件的字节码结构
[user defined type] structure, union, enumeration
Slam d'attention: un slam visuel monoculaire appris de l'attention humaine
【JVM调优实战100例】04——方法区调优实战(上)
Linear algebra of deep learning
第四篇,STM32中断控制编程
ZYNQ移植uCOSIII
pyflink的安装和测试
threejs图片变形放大全屏动画js特效
Data sharing of the 835 postgraduate entrance examination of software engineering in Hainan University in 23
随机推荐
Advanced learning of MySQL -- basics -- transactions
View remote test data and records anytime, anywhere -- ipehub2 and ipemotion app
深度学习简史(一)
第五篇,STM32系统定时器和通用定时器编程
ActiveReportsJS 3.1中文版|||ActiveReportsJS 3.1英文版
Equals() and hashcode()
【JokerのZYNQ7020】AXI_EMC。
代码克隆的优缺点
New feature of Oracle 19C: automatic DML redirection of ADG, enhanced read-write separation -- ADG_ REDIRECT_ DML
重上吹麻滩——段芝堂创始人翟立冬游记
Let's talk about 15 data source websites I often use
迈动互联中标北京人寿保险,助推客户提升品牌价值
Learn to use code to generate beautiful interface documents!!!
paddlehub应用出现paddle包报错的问题
【JVM调优实战100例】05——方法区调优实战(下)
tensorflow 1.14指定gpu运行设置
Js+svg love diffusion animation JS special effects
Chapter 5 DML data operation
深度学习之环境配置 jupyter notebook
Dell Notebook Periodic Flash Screen Fault