当前位置:网站首页>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)
边栏推荐
- JS general form submission 1-onsubmit
- Folic acid modified metal organic framework (zif-8) baicalin loaded metal organic framework composite magnetic material (AU- [email
- How to use lxml to judge whether the website announcement is updated
- selenium 浏览器(1)
- SQL Injection (GET/Search)
- 挡不住了,国产芯片再度突进,部分环节已进到4nm
- Go language web development series 26: Gin framework: demonstrates the execution sequence of code when there are multiple middleware
- 金属有机骨架MIL-88负载阿霉素DOX|叶酸修饰UiO-66-NH2负载阿霉素[email protected]纳米粒子
- Conversion function and explicit
- jvm-类加载
猜你喜欢
[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)"/>MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)

Go language web development series 30: gin: grouping by version for routing

Qt学习17 对话框及其类型

Qt学习24 布局管理器(三)

掌握Cypress命令行选项,是真正掌握Cypress的基础

MySQL data processing value addition, deletion and modification

Implementation of Muduo asynchronous logging

SQL Injection (GET/Search)
[email protected] Nanoparticles) | nano metal organic framework carry"/>Metal organic framework material zif-8 containing curcumin( [email protected] Nanoparticles) | nano metal organic framework carry

解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)
随机推荐
Flutter dynamic | fair 2.5.0 new version features
Logback log sorting
[technology development-24]: characteristics of existing IOT communication technology
[combinatorics] permutation and combination (examples of combinatorial number of multiple sets | three counting models | selection problem | combinatorial problem of multiple sets | nonnegative intege
如何使用lxml判断网站公告是否更新
Unity render streaming communicates with unity through JS
Qt学习22 布局管理器(一)
Similarities and differences of sessionstorage, localstorage and cookies
PhpMyAdmin stage file contains analysis traceability
Shell timing script, starting from 0, CSV format data is regularly imported into PostgreSQL database shell script example
[combinatorics] permutation and combination (two counting principles, examples of set permutation | examples of set permutation and circle permutation)
Go 1.16.4: manage third-party libraries with Mod
SQL Injection (POST/Search)
QT learning 17 dialog box and its types
Installation impression notes
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
JS new challenges
IBEM mathematical formula detection data set
Implementation of Muduo asynchronous logging
解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)