当前位置:网站首页>JVM object lifecycle
JVM object lifecycle
2022-07-03 14:00:00 【It's hard to choose a name】
List of articles
jvm The life cycle of the object in

Create a stage
(1) Allocate storage space for objects
(2) Start constructing objects
(3) From superclass to subclass pair static Members are initialized
(4) Superclass member variables are initialized in order , Recursively calls the constructor of the superclass
(5) Subclass member variables are initialized in order , Subclass construct method call , And once the object is created , And assigned to some variables
value , The shape of this object State switches to the application stage
Application stage
(1) The system maintains at least one strong reference to the object (Strong Reference)
(2) All references to this object are strong references ( Unless we explicitly use : Soft citation (Soft Reference)、
Weak reference (Weak Reference) Or virtual reference (Phantom Reference))
The definition of reference :
1. Our data type must be reference type
2. The data stored in our type of data must be the starting address of another piece of memory
Invisible stage
Objects in the invisible phase can no longer find direct or indirect strong references in the object root reference collection of the virtual machine , The most common is temporary variables in threads or functions . Programs no longer hold strong references to objects .( But static variables of some classes or JNI It is possible to hold )
Unreachable stage
It means that the object is no longer held by any strong reference ,GC It is found that the object is unreachable
The difference from the invisible stage is : Unreachable is after Algorithm
So what are the algorithms ?
Reference count :
Object has a reference to +1, Remove a reference and -1, When the number of references is 0 It is considered that there is no quotation , Recyclable
problem : Can't solve the problem of circular dependency

Accessibility analysis : adopt GC Root The object of , Start looking down , See if an object can reach
What can be regarded as GC ROOT: loader 、Thread、 Local variable table of virtual machine stack 、static member 、 const reference 、
Variables of the local method stack are essentially a set of active references

Collection phase
See whether the object needs to be executed finalize Method :
If you don't need to : Virtual machine has been called finalize Methods or objects are not overridden finalize Method , Then the object can be recycled
need : The virtual machine puts objects into F-queue, Create a low priority thread to execute the objects in the queue finalize Method
finalize Method to re establish the reference connection for the object
yes : The virtual machine moves the object out F-queue queue , Object returns to the application stage
no : Objects can be recycled
finalize Methods can affect JVM The object of the allocation and the recycling speed finalize Methods may revive objects
The end stage
Object's finalize() After the function is executed , The object is still unreachable , This object is the process termination stage .
Object memory space reallocation phase
GC Reclaim or reallocate the memory space occupied by this object , The object disappeared completely
out of memory
1、 Heap memory overflow :java.lang.OutOfMemoryError: GC overhead limit exceeded
-Xmx20M : The maximum size that can be expanded when the program runs
-Xms20M: Initialize heap size
2、 Method area memory overflow :java.lang.OutOfMemoryError: Metaspace
-XX:MetaspaceSize: Initialize method area size
-XX:MaxMetaspaceSize: The maximum size that can be expanded when the program runs
3、 Occupy memory overflow :java.lang.StackOverflowError
-Xss: The size of the stack ( Default 1M)
边栏推荐
- 【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明
- NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
- Richview trvstyle liststyle list style (bullet number)
- [technology development-24]: characteristics of existing IOT communication technology
- 怎样删除对象的某个属性或⽅法
- GoLand 2021.2 configure go (go1.17.6)
- JS general form submission 1-onsubmit
- Flutter dynamic | fair 2.5.0 new version features
- Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
- UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
猜你喜欢
![[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes](/img/f3/a219fe8e7438b8974d2226b4c3d4a4.png)
[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes

jvm-运行时数据区

【吉林大学】考研初试复试资料分享

3D vision - 2 Introduction to pose estimation - openpose includes installation, compilation and use (single frame, real-time video)

Go language web development series 28: solve cross domain access of CORS with gin contrib / CORS
![[technology development-24]: characteristics of existing IOT communication technology](/img/f3/a219fe8e7438b8974d2226b4c3d4a4.png)
[technology development-24]: characteristics of existing IOT communication technology
![Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:](/img/2f/33504391a661ecb63d42d75acf3a37.png)
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:

全面发展数字经济主航道 和数集团积极推动UTONMOS数藏市场

Installation impression notes

Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm
随机推荐
UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
selenium 浏览器(1)
Go 1.16.4: purpose of go mod tidy
Implementation of Muduo accept connection, disconnection and sending data
[技術發展-24]:現有物聯網通信技術特點
MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)
Spring cup eight school league
又一个行业被中国芯片打破空白,难怪美国模拟芯片龙头降价抛售了
Uniapp tips - set background music
How to use lxml to judge whether the website announcement is updated
Use vscode to view hex or UTF-8 codes
解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)
Multi person collaborative data annotation based on Baidu brain easydata from scratch
Use docker to build sqli lab environment and upload labs environment, and the operation steps are provided with screenshots.
[ACNOI2022]猜数
Qt学习23 布局管理器(二)
可编程逻辑器件软件测试
Qt学习20 Qt 中的标准对话框(中)
HALCON联合C#检测表面缺陷——HALCON例程autobahn
Mastering the cypress command line options is the basis for truly mastering cypress