Will the member variables inside the java outer object be reclaimed by the garbage collector after the outer object is left empty?

public class Person{
    public Man m;
}

Person p = new Person();
Man man=new Man();
p.m = man;

//do other things

p = null;

System.gc();

when p=null is set, will the object m be recycled with p the next time gc?

Sep.03,2021

you need to determine whether there are other strong references in man. Gc will only drop when the root object cannot be found


if there are no other references from the root node to m, then it will

Menu