当前位置:网站首页>memory thrashing
memory thrashing
2022-06-28 18:42:00 【Novice Xiaowang】
One . Memory jitter
1. Memory jitter : It refers to the phenomenon that a large number of objects are created or recycled in a short time .
2. Causes of memory jitter : Mainly frequent ( Very important ) Create objects in loops ( A large number of objects are created in a short time , Because new objects occupy memory space and are frequent , If you create an object in a loop once or twice, it has little effect on memory , It will not cause serious memory jitter, which is acceptable and inevitable , Frequently, the memory jitter is very serious ), The effect of memory jitter is if the jitter is frequent , Will cause the garbage collection mechanism to run frequently ( Generate a large number of objects in a short time , Need a lot of memory , And still shake frequently , You may need to reclaim memory for generating objects , The garbage collection mechanism will naturally run frequently ).
3. Memory jitter affects : Frequent memory jitter can cause garbage collection to run frequently , Cause the system to jam .
Solution
Where are the common memory jitters ?
1.Android Of onDraw, onMeasure Method .
here , The authorities do not recommend creating objects here , Why? ? I see , It is frequently called by the bottom layer ,( You can learn about the Android refresh mechanism ), If you create a large number of objects , Frequent recycling , Memory jitter is easy . If it is bitmap, His memory is in native The distribution of , Processing needs to go through the kernel , Make the waiting time longer .
2. Handle io The place of
Read and write files , The memory stream creates a large number of byte[] The object will appear .
3. Produce components of the consumer model , These frequently produce a large number of objects , Like logs , Embedded point components, etc
4. Complex type json analysis .
such as Gson. By default , Is to generate new instances through reflection . Using the object pool through the adapter can solve
Recommend solutions :
adopt Reuse objects Use to solve memory jitter ,
For example, enjoy yuan design pattern , Object pool scheme . But object pooling does not reduce memory , You need to limit the memory , And each object scene is different , You may need to filter . need lru Data structure of the algorithm, etc . May refer to handler,glide Object pool principle .
The principle of object pooling is simple , It is to create objects and store them in memory after use , For example, save it in the linked list , The next time you use an object , Look it up in the linked list first , If there is, take it out , If not, create , This avoids the creation of a large number of objects
边栏推荐
猜你喜欢

Small program graduation project based on wechat subscription water supply mall small program graduation project opening report function reference

How to design a business high performance and high availability computing architecture - job

Sharing-JDBC分布式事务之Seata实现

IDM certification process log embedding point description

konva系列教程3:自定义图形

HackTheBox-baby CachedView

io模型初探

About Significance Tests

Seata implementation of sharing JDBC distributed transaction

NFT流动性协议的安全困局—NFT借贷协议XCarnival被黑事件分析
随机推荐
Huawei cloud AOM released version 2.0, and three features appeared
CORBA 架构体系指南(通用对象请求代理体系架构)
Lumiprobe非荧光炔烃研究丨DBCO NHS 酯
抗兔Dylight 488丨Abbkine通用型免疫荧光(IF)工具箱
匿名函数this指向以及变量提升
Mycat+ sub database and sub table
About Significance Tests
微信小程序接入百度统计报错 Cannot read property ‘mtj‘ of undefined
FFmpeg学习总结
杂记:数据库go,begin,end,for,after,instead of
Steam education to break the barriers between disciplines
第2章 处理文件、摄像头和图形用户界面cameo应用
Voice network VQA: make the user's subjective experience of unknown video quality in real-time interaction known
WiFi安全漏洞KRACK深度解读
安装nodejs环境
Operations research note
【C#】详解值类型和引用类型区别
select/poll/epoll
Go 降序排序 取 Top N
SqlTransaction