I want to understand how Java's GC works on nested objects. For eg.
class ObjA {
ObjB b;
}
class ObjB {
ObjC c;
}
class ObjC {
Prop1 p1;
Prop2 p2;
Prop3 p3;
}
If ObjA has a reference of ObjB and ObjB has a reference of ObjC, etc similar to russian dolls, we get the point When I make ObjA null, that is there is no reference to Obj A (Object A is not reachable) what happens to ObjB and ObjC
I know they are garbage collected, but when? Does it happen in the same pass. Now if this hierarchy is deep with each object containing n properties, are all this referenced properties garbage collected in one pass?
Does this vary based on the type of Garbage Collection (eg. G1, CMS, etc)? Should I be concerned about how these are handled while building complex data structures? If not, why?
Will such deep hierarchy affect GC, heap and application performance?
Aucun commentaire:
Enregistrer un commentaire