当前位置:网站首页>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;
}
边栏推荐
- Chenglian premium products has completed the first step to enter the international capital market by taking shares in halber international
- Hero League | King | cross the line of fire BGM AI score competition sharing
- Stm32f407 ------- SPI communication
- 随时随地查看远程试验数据与记录——IPEhub2与IPEmotion APP
- fastDFS数据迁移操作记录
- [software reverse automation] complete collection of reverse tools
- 【JokerのZYNQ7020】AXI_EMC。
- threejs图片变形放大全屏动画js特效
- Link sharing of STM32 development materials
- Let's talk about 15 data source websites I often use
猜你喜欢
ZYNQ移植uCOSIII
深度学习之线性代数
Chapter II proxy and cookies of urllib Library
[software reverse - solve flag] memory acquisition, inverse transformation operation, linear transformation, constraint solving
[C language] dynamic address book
迈动互联中标北京人寿保险,助推客户提升品牌价值
[yolov5 6.0 | 6.1 deploy tensorrt to torch serve] environment construction | model transformation | engine model deployment (detailed packet file writing method)
Batch obtain the latitude coordinates of all administrative regions in China (to the county level)
Dr selection of OSPF configuration for Huawei devices
Part V: STM32 system timer and general timer programming
随机推荐
C9高校,博士生一作发Nature!
Data processing of deep learning
Notes of training courses selected by Massey school
New feature of Oracle 19C: automatic DML redirection of ADG, enhanced read-write separation -- ADG_ REDIRECT_ DML
threejs图片变形放大全屏动画js特效
Advanced learning of MySQL -- basics -- multi table query -- joint query
stm32F407-------SPI通信
Value Function Approximation
建立自己的网站(17)
深度学习之线性代数
Mujoco second order simple pendulum modeling and control
Deep understanding of distributed cache design
Lombok 同时使⽤ @Data 和 @Builder 的坑,你中招没?
深度学习之环境配置 jupyter notebook
【批處理DOS-CMD命令-匯總和小結】-字符串搜索、查找、篩選命令(find、findstr),Find和findstr的區別和辨析
Zynq transplant ucosiii
Dr selection of OSPF configuration for Huawei devices
Chapter 5 DML data operation
Summary of being a microservice R & D Engineer in the past year
ZYNQ移植uCOSIII