当前位置:网站首页>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;
}边栏推荐
- Model-Free Control
- Dell笔记本周期性闪屏故障
- stm32F407-------SPI通信
- equals()与hashCode()
- Deep understanding of distributed cache design
- .class文件的字节码结构
- [Batch dos - cmd Command - Summary and Summary] - String search, find, Filter Commands (FIND, findstr), differentiation and Analysis of Find and findstr
- String comparison in batch file - string comparison in batch file
- Attention slam: a visual monocular slam that learns from human attention
- [牛客] [NOIP2015]跳石头
猜你喜欢

详解OpenCV的矩阵规范化函数normalize()【范围化矩阵的范数或值范围(归一化处理)】,并附NORM_MINMAX情况下的示例代码

Activereportsjs 3.1 Chinese version | | | activereportsjs 3.1 English version

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

【软件逆向-自动化】逆向工具大全

ActiveReportsJS 3.1中文版|||ActiveReportsJS 3.1英文版
![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
![[software reverse automation] complete collection of reverse tools](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[software reverse automation] complete collection of reverse tools

windows安装mysql8(5分钟)

Trace tool for MySQL further implementation plan

Dell Notebook Periodic Flash Screen Fault
随机推荐
STM32开发资料链接分享
Levels - UE5中的暴雨效果
from .cv2 import * ImportError: libGL.so.1: cannot open shared object file: No such file or direc
Slam d'attention: un slam visuel monoculaire appris de l'attention humaine
Advanced learning of MySQL -- Fundamentals -- concurrency of transactions
Link sharing of STM32 development materials
学习光线跟踪一样的自3D表征Ego3RT
「精致店主理人」青年创业孵化营·首期顺德场圆满结束!
Building a dream in the digital era, the Xi'an station of the city chain science and Technology Strategy Summit ended smoothly
Mujoco produces analog video
Quaternion attitude calculation of madgwick
[force buckle]41 Missing first positive number
Dell笔记本周期性闪屏故障
C Primer Plus Chapter 14 (structure and other data forms)
Use mujoco to simulate Cassie robot
学习使用代码生成美观的接口文档!!!
【批处理DOS-CMD命令-汇总和小结】-查看或修改文件属性(ATTRIB),查看、修改文件关联类型(assoc、ftype)
Advanced learning of MySQL -- basics -- multi table query -- joint query
Advanced learning of MySQL -- basics -- multi table query -- inner join
Address information parsing in one line of code