Garbage Collection
2 posts in topic
Flat View  Flat View

Posted By:   vivek_gupta
Posted On:   Friday, January 10, 2003 12:14 AM

i declare a HashMap(say A) in a method (say M1)and add the reference of another HashMap (say B) in HashMap "A". Now when the processing comes out of method "M1"(and eventually "A" is also out of the scope and hence can't be referenced now) and the HashMap "B" is still alive and is referenced by some other process, will the Garbage Collector clear away HashMap "A" or it will first clear HashMap "B"?

Re: Garbage Collection

Posted By:   Viral_Shah  
Posted On:   Friday, January 10, 2003 02:56 AM

the garbage collector collects the objects which are NOT BEING REFERED by anybody... the object itself may be refering to some more objects, but if there is no way accessing the object itself, its references also becomes useless.. and thefore, the references are also released.

however, as in your case, the objects refered by the garbage-collect object may be kept alive if they are being refered by some other objects.


Re: Garbage Collection

Posted By:   Lasse_Koskela  
Posted On:   Friday, January 10, 2003 12:29 AM

The "outer" HashMap 'A' is up for garbage collection after 'M1()' because there are no references to 'A'.

It doesn't matter how many references 'A' has to other objects. The only thing that matters is that 'A' isn't accessible by anyone (and you can't get a reference to an enclosing HashMap through an object contained in it).

About | Sitemap | Contact