dcsimg
Garbage collection
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   puneet_narang
Posted On:   Tuesday, December 4, 2001 08:09 AM

if a method is called on an object like this
new ClassA().methodA()

Is this object eligible for garbage collection after method is finished?

thanks

Re: Garbage collection

Posted By:   Bozidar_Dangubic  
Posted On:   Tuesday, December 4, 2001 08:31 AM

any object is eligible for garbage collection after there is no more reference to the object from any other object. so if you instantiate a class and call a method on it, that does not necessarily mean that after method invocation is completed the object is eligible for garbage collection. once there are no more reference to the object it becomes eligible for garbage collection. creating an object and later setting its reference to null

SomeObj obj = new SomeObj();
obj.methodA();
....
// here obj is not eligible for garbage collection since there is still live reference to the object
obj = null ;
// now, obj is eligible for garbage collection.

will make it eligible for GC.
About | Sitemap | Contact