Java garbage collection (translation)

Source: Internet
Author: User

Original: Https://plumbr.eu/handbook/garbage-collection-in-java

  

It has always been an important task to collate and explain the garbage collection mechanism. In practical applications, you need to know how to modify the settings to meet the actual needs.

For example, let's look at how the JVM (virtual machine) is set up to ensure that we can allocate these resources correctly.

Fragmentation and compression

When the JVM is garbage collected, you must ensure that sufficient resources are available for allocation. This creates a memory fragment that, like disk fragmentation, causes two problems:

* To find a sufficient space, the write operation becomes more time consuming, it is no longer a simple operation

* When creating a new object, the virtual machine allocates memory in the adjacent block. If there are more and more fragments, reaching a point where there is not enough free debris to create new objects,

An allocation error is generated.

To avoid this problem, the virtual machine must ensure that the number of fragments cannot exceed the limit. So the process of memory cleanup and release also occurs in garbage collection, just to replace tokens and to clear fragments. This process will reassign all the objects that can be collected to a new place, eliminating fragmentation. Below is an illustration of the effect:

Generational assumptions

As we mentioned earlier, garbage collection needs to stop all applications. It is clear that with the increasing number of objects, the number of garbage collection will be more and more.

If we had only a small piece of memory space, the researchers observed that most memory allocations fall into two main categories:

* Most objects quickly become useless

* There's one more that won't survive for a long time

  

These data values are put together as a hypothesis, based on the assumption that the memory of the virtual machine is divided into the younger generation and the old age, which is also known as the Elder generation

There are many algorithms for how to clean up these memory spaces in parallel and separately, and have been trying for a long time to improve the performance of garbage collection.

It is not that there is a problem-free approach, such as a cross-reference between objects from different generations, how to calculate garbage back, and collect data from this generation.

It is worth noting that these assumptions are not true for some applications. Because the garbage collection algorithm has optimized the disappearing young generation or the likely surviving old generation,

Virtual opportunities enable objects that are collected quickly to have the desired life cycle.

Memory pool

Not finished ....

Java garbage collection (translation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.