What is the direct object is referenced GC Roots?

When CMS garbage collector garbage collection will be divided into four stages: initial mark, concurrent mark and re-mark, concurrent cleanup. Which marks the initial stage will be "Stop the world", and reclaim the object is a direct reference to the GC Roots, this process is very short, the impact on the normal operation of the system is very small.

The target here is a direct reference to the GC Roots is how objects?

We look at the following piece of code like this:

public class Order {
	public static User user = new User();
}

public class User {
	private Position position = new Position();
}

First, we should know GC Roots is a class static variable or a local variable method . Here we can easily see, user belongs to the class of static variables, and the User object is an object to be a direct reference to the user, so the User object is a direct reference to the GC Roots.

position is a class instance variable, neither static class variable local variables nor the method, it is not an object GC Roots, Position reference target position is not directly referenced GC Roots.

The initial mark

Initial marking process as shown above, User objects directly referenced GC Roots will be marked, Position object indirect reference has not been marked.

Guess you like

Origin www.cnblogs.com/shuiyj/p/12640710.html