A little bit of knowledge of garbage collection

Source: Internet
Author: User

Two days ago, I was asked a question about the closed-loop problem in garbage collection, which is probably the problem

A=B.V;

B=C.V;

C=A.V;

If you kill A,b,c, then the memory allocated in the heap memory will not be recycled.

First draw the memory graph


This is a simple diagram, and first we know that it forms a closed loop, can be a simple look at the knowledge of garbage collection, you can know what is closed loop, the garbage collection mechanism has two methods, one is the counting method, as the name implies is to assign a private number for the object, if the count is called once will add one, The count is zero and will be reclaimed, but there is a closed-loop problem, such as this problem, three call each other, but there is no real meaning, should be recycled, with the method of counting can not be recycled, so in order to avoid this problem, we now use the root set algorithm to start traversing the reference relationship from Dcroot, Can traverse the call reference can be reached, not to reach the call unreachable, can not reach will be recycled, so in the heap memory allocated memory space will be recycled. Down-to-earth, mutual encouragement.

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.