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.