当前位置:网站首页>How GC determines whether an object can be recycled
How GC determines whether an object can be recycled
2022-06-25 15:30:00 【ITenderL】
GC How to judge whether an object can be recycled
- Reference counting : Each object has a reference counter , When adding a reference, the counter is incremented 1, Counter decrement on reference release 1, When count is 0 when , Recyclable .
- Reachability algorithm : from GC Roots Start looking down , The search path is the reference chain . When an object arrives GC Roots When there is no reference chain , Then prove that this object is not available , Then the virtual opportunity judgment is a recyclable object .
Reference counting , There may be A Refer to the B,B Also cited A, Even if they don't use it anymore , But because of mutual reference Counter =1 Can never be recycled .
It can be used as GC Roots There are :
- Virtual machine stack ( Table of local variables in stack frame ) Object referenced in
- Object referenced by static property of method area
- Objects referenced by static constants in the method area
- Local method stack JNI(Native Method ) Referenced object
Unreachable objects are not recycled immediately
The unreachable objects in the reachability algorithm do not die immediately , The object has a chance to save himself . It takes at least two marking processes for an object to be declared dead by the system : For the first time, accessibility analysis found that there was no relationship between GC Roots Linked reference chain , The second one was created automatically by the virtual machine Finalizer Queue to determine whether it needs to be executed finalize() Method .
When the object becomes (GC Roots) Unreachable time ,GC It will determine whether the object covers finalize Method , If not covered , Then recycle it directly . otherwise , If the object has not been executed finalize Method , Put it in the F-Queue queue , The... Of the objects in the queue is executed by a low priority thread finalize Method . perform finalize After the method ,GC Whether the object is reachable will be judged again , If you can't reach , Then recycle , otherwise , object “ resurrection ” Each object can only be triggered once finalize() The method is due to finalize() Methods are expensive to run , High uncertainty , The order in which the individual objects are invoked cannot be guaranteed , It's not recommended , Suggest forgetting it .
边栏推荐
- Postman usage notes, interface framework notes
- MySQL field truncation principle and source code analysis
- [paper notes] semi supervised object detection (ssod)
- [paper notes] overview of case segmentation
- Yolov5 Lite: fewer parameters, higher accuracy and faster detection speed
- Js- get the mouse coordinates and follow them
- Principle and implementation of MySQL master-slave replication (docker Implementation)
- One question per day,
- Pytorch | how to save and load pytorch models?
- QT pattern prompt box implementation
猜你喜欢

Several common optimization methods

User defined data type - structure

Source code analysis of zeromq lockless queue
![[paper notes] rethinking and improving relative position encoding for vision transformer](/img/6b/8b1c192e0ce715789465fa9ccaabfc.jpg)
[paper notes] rethinking and improving relative position encoding for vision transformer

Dynamic memory allocation

Solution of push code failure in idea

System Verilog — interface

Shared memory synchronous encapsulation

‘make_ unique’ is not a member of ‘std’

Fishing detection software
随机推荐
Postman usage notes, interface framework notes
Afterword of Parl intensive learning 7-day punch in camp
‘make_ unique’ is not a member of ‘std’
Design and implementation of thread pool
程序员 VS 黑客的思维 | 每日趣闻
Breakpad usage and DMP analysis
Source code analysis of synergetics and ntyco
Learning C language today is the first time to learn C language. In college, C linguistics is not good, but I want to make progress, so I found a beep video on the Internet to learn C language
Bessie's weight problem [01 backpack]
Paddlepaddle paper reproduction course biggan learning experience
Summary of regularization methods
Sampling method and descriptive statistical function in R language
Boost listening port server
QT pattern prompt box implementation
AB string interchange
Solve the go project compilation error go mod: no such file or directory
JMeter reading and writing excel requires jxl jar
The last glory of the late Ming Dynasty - the battle of Korea
Netlogo learning
2. operator and expression multiple choice questions