当前位置:网站首页>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 .
边栏推荐
- Why do I need message idempotence?
- 国信金太阳靠谱吗?是否合法?开股票账户安全吗?
- Source code analysis of synergetics and ntyco
- [paper notes] street view change detection with deconvolutional networks
- Boost listening port server
- Paddlepaddle paper reproduction course biggan learning experience
- A deformation problem of Hanoi Tower
- Agent and classloader
- QT article outline
- ‘make_ unique’ is not a member of ‘std’
猜你喜欢
![[paper notes] mcunetv2: memory efficient patch based influence for tiny deep learning](/img/4b/f446bd37057237c0ba4c7b4e38e74f.jpg)
[paper notes] mcunetv2: memory efficient patch based influence for tiny deep learning

Record the time to read the file (the system cannot find the specified path)

Ubuntu 20.04 installing mysql8.0 and modifying the MySQL password

Character encoding minutes

Js- get the mouse coordinates and follow them

Source code analysis of zeromq lockless queue

Solution of push code failure in idea

System Verilog — interface

Completabilefuture of asynchronous tools for concurrent programming

One question per day,
随机推荐
Day01: learning notes
The last glory of the late Ming Dynasty - the battle of Korea
System Verilog - function and task
程序员 VS 黑客的思维 | 每日趣闻
BM setup process
Work of the first week
Kali modify IP address
Why should the coroutine be set to non blocking IO
国信金太阳靠谱吗?是否合法?开股票账户安全吗?
Basic knowledge of pointer
Detailed summary of reasons why alertmanager fails to send alarm messages at specified intervals / irregularly
Learning notes on February 8, 2022 (C language)
Detailed description of crontab command format and summary of common writing methods
Some usage records about using pyqt5
Review of arrays and pointers triggered by a topic
Two advanced playing methods of QT signal and slot
MySQL field truncation principle and source code analysis
Boost listening port server
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