当前位置:网站首页>Learn garbage collection 01 of JVM -- garbage collection for the first time and life and death judgment
Learn garbage collection 01 of JVM -- garbage collection for the first time and life and death judgment
2022-07-05 12:15:00 【The king of early rising】
If this article is the first time you intend to learn about garbage collection , With pleasure , I should not miss people's future . Ha ha ha ha ha ha ha ha ha
Catalog
Reachability analysis algorithm
Attention! : Unreachable does not mean “ There is no doubt that I will die ”
What is garbage collection ?
Also called garbage collection mechanism , English is Garbage Collector, abbreviation GC.
Garbage collection is to recycle unused data in memory , Free up memory .
There are three problems that need to be solved :
- Who is rubbish ?( Which memory to recycle )
- When to collect ?
- How to collect it ?
Who is rubbish ?
Java Language , Everything is the object . We put “ die ” The object of is treated as garbage .
die : It means that it can no longer be used in any way . It can be understood in this way : We can't find this object , The reference of this object has been invalidated , Cannot be located , Can't be used .
There are two main ways to judge the life and death of an object :
- Reference counting algorithm
- Reachability analysis algorithm
Reference counting algorithm
Object when referenced , Count +1;
When a reference on a body fails , Count -1.
When the reference count of an object is 0 when , It can be considered that there is no quotation on him , already “ die ”.
But there will be some accidents in this method , It often needs other methods to solve these unexpected situations .
such as : Imagine the two nodes of the linked list A and B Only have the reference of the other party . But no one next = A perhaps B. node A、B Has lost contact with the head node . At this time, these two objects can no longer be accessed , The reference count on both objects is not 0 .
A.next = B
B.next = AReachability analysis algorithm
Java This is the algorithm used .
Algorithm ideas : Call a series “GC Roots” As the starting node set , Start with these nodes , Search down by reference , The path of the search process is called “ References to the chain ”, If an object arrives at GC Roots There is no reference chain between , From GC Roots When this object is not reachable , It is proved that this object can no longer be used .
GC Roots It can be understood as a reference starting point that can be directly accessed .
Attention! : Unreachable does not mean “ There is no doubt that I will die ”
Reachability analysis algorithm in judging death , It takes at least two markups .
If the object is found to have no relationship with GC Roots Linked reference chain , Then it will be marked for the first time .
Check whether the object needs to execute finalize() Method ( The relevant introduction is below ), If it is necessary to carry out , It is called F-Queue In the queue of . If in execution finalize() After method , Object becomes reachable , Is removed from the queue . The rest in the queue will be marked twice , Basically declared dead . If it is not necessary to perform , Then there's no nonsense , It's not saved , Die straight away .
finalize() The method is Object Class , stay GC( Short for garbage collection ) Before you are ready to free up the memory space occupied by the object , It will first call finalize() Method .
Keep early hours , take care . The king of early rising wishes you good luck .
边栏推荐
- 只是巧合?苹果 iOS16 的神秘技术竟然与中国企业 5 年前产品一致!
- 【TFLite, ONNX, CoreML, TensorRT Export】
- [mainstream nivida graphics card deep learning / reinforcement learning /ai computing power summary]
- Redis cluster (master-slave) brain crack and solution
- Two minutes will take you to quickly master the project structure, resources, dependencies and localization of flutter
- GPS数据格式转换[通俗易懂]
- Codeforces Round #804 (Div. 2)
- Semantic segmentation experiment: UNET network /msrc2 dataset
- Why do you always fail in automated tests?
- Seven ways to achieve vertical centering
猜你喜欢
![[calculation of loss in yolov3]](/img/8c/1ad99b8fc1c5490f70dc81e1e5c27e.png)
[calculation of loss in yolov3]

Embedded software architecture design - message interaction

多表操作-自关联查询

【主流Nivida显卡深度学习/强化学习/AI算力汇总】

1 plug-in to handle advertisements in web pages
调查显示传统数据安全工具在60%情况下无法抵御勒索软件攻击

Master the new features of fluent 2.10

互联网公司实习岗位选择与简易版职业发展规划

【pytorch 修改预训练模型:实测加载预训练模型与模型随机初始化差别不大】

Get data from the database when using JMeter for database assertion
随机推荐
Ncp1342 chip substitute pn8213 65W gallium nitride charger scheme
Hiengine: comparable to the local cloud native memory database engine
1. Laravel creation project of PHP
[singleshotmultiboxdetector (SSD, single step multi frame target detection)]
【ijkplayer】when i compile file “compile-ffmpeg.sh“ ,it show error “No such file or directory“.
Two minutes will take you to quickly master the project structure, resources, dependencies and localization of flutter
Sentinel sentinel mechanism of master automatic election in redis master-slave
Xi IO flow
MySQL basic operation -dql
Troubleshooting of high memory usage of redis in a production environment
ABAP table lookup program
Application of a class of identities (vandermond convolution and hypergeometric functions)
What is digital existence? Digital transformation starts with digital existence
7月华清学习-1
Get all stock data of big a
Swift - add navigation bar
Use and install RkNN toolkit Lite2 on itop-3568 development board NPU
调查显示传统数据安全工具在60%情况下无法抵御勒索软件攻击
Video networkstate property
【load dataset】