Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the process of Java garbage collection?

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "what is the process of Java garbage collection". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

A remarkable feature of the Java language is the introduction of garbage collection mechanism, which is clear to everyone, and the concept of garbage collection is not introduced here. The point is when does garbage collection start? What have you done to what?

When does GC start:

All collector types are implemented based on generational technology, so it is important to know how objects are divided according to their lifecycles.

Younger generation: divided into three areas: the original area (Eden) and two small survival areas (Survivor), the two survival areas are divided into From and To according to function. The vast majority of objects are allocated in the original area, and more than one object that is still alive in the garbage collection operation is placed in the survival area. The vast majority of garbage collection occurs in the younger generation.

Older generation: stores objects in the younger generation that are still alive after multiple recycling cycles, and may also be allocated directly to the permanent generation for some large memory allocations.

Persistent generation: stores classes, methods, and their descriptions, where there is little garbage collection.

With the above groundwork, start to answer when GC will start:

When the Eden memory is full, start Minor GC (memory recovery from the younger generation is called Minor GC); start Full GC when the space required by objects in the old age is greater than the remaining space in the old age (but may also be less than the remaining space, Full GC is forced by the HandlePromotionFailure parameter)

Operate on something, that is, what is the object of garbage collection:

Starting with root, there are no reachable objects, and after the first marking and cleaning, there are still no resurrected objects.

What have you done:

It mainly does the work of cleaning up objects and sorting out memory. The specific extension is as follows

Type of garbage collector:

Serial garbage collector (Serial Garbage Collector)

Parallel garbage collector (Parallel Garbage Collector)

Concurrent tag scan garbage collector (CMS Garbage Collector)

G1 garbage Collector (G1 Garbage Collector)

Garbage collection algorithm:

Citation counting method

Label elimination method

Replication algorithm

Label compression algorithm

Generation algorithm

Partition algorithm

You can learn about the above for yourself. Here are a few related articles:

Memory region Partition of JVM

Carding of JVM knowledge points

JVM memory allocation and recovery

JVM memory management mechanism

Java virtual machine learning-garbage collector

The loading process of classes in the virtual machine

Load Loading:

A binary byte stream is obtained through the fully qualified name of a class, the static storage structure represented by the byte stream is transformed into the runtime data structure of the method area, and a java.lang.Class object representing the class is generated in memory as the access entry for all kinds of data of the class in the method area.

Verify Verification:

Ensure that the information contained in the byte stream of the Class file meets the requirements of the current virtual machine and does not compromise the security of the virtual machine itself.

Prepare Preparation:

Formally allocate memory to the class variable and set the initial value of the class variable.

Parse Resolution:

The process by which a virtual machine replaces symbolic references within a constant pool with direct references.

Initialize Initialization:

This is the last step in the class loading process that actually starts executing the Java program code defined in the class.

Use Using:

Execute according to the behavior defined by the program code you write.

Uninstall Unloading:

GC is responsible for uninstalling, and this section is generally not discussed.

You are welcome to leave a message about the class loading process more clearly. You can read related articles:

Detailed explanation of class loader

Explain the life cycle of the java class in detail

Talk about my understanding of object-oriented and classes and objects.

The relationship between strong reference, soft reference, weak reference, virtual reference and GC

Strong references: references such as objects out of new will never be recycled as long as strong references remain.

Soft references: objects that are referenced but not necessary, recycled before memory overflow exceptions.

Weak references: non-essential objects that can only survive until the next garbage collection occurs.

False reference: has no effect on survival time and is notified during garbage collection.

This is the end of the content of "what is the process of Java garbage collection". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report