"Java Starter series" garbage collection

Source: Internet
Author: User
Garbage collection

Without garbage collection, memory will be consumed sooner or later because we are constantly allocating memory space without recycling. Unless the memory is infinitely large, we can be self-willed and not recycled, but that is not the case.

Garbage collection actually did two things: 1, found useless objects; 2. Reclaim memory space occupied by useless objects.

Garbage collection algorithm

1. Application Counting method

Object, a counter value of +1 is added whenever a reference to the object is referenced, and the counter value is 1 when the reference is invalidated. Any object with a count value of 0 at any time is impossible to be used again. This algorithm uses a lot of scenarios, but the algorithm is not used in Java because it is difficult to solve the case of mutual reference between objects.

2, the application can reach the law

By a series of objects called "GC Roots" as starting points, searching down from these nodes, the path traversed by the search is called the reference chain, and when an object to the GC Roots does not have any reference chain (that is, the GC Roots to the object is unreachable), it proves that the object is not available.

Generation of garbage collection

"Java Starter series" garbage collection

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.