Discussion :: Garbage Collections - General Questions (Q.No.2)
|Sukanya said: (Jun 24, 2012)|
|What mean by garbage collection ?|
|Basha said: (Sep 24, 2012)|
|Garbage collection is a one of the program in Jvm.I take the responsibel to remove the unnecessory object form memory. The garbage collection call the finalize() method before removing the object form jvm's memory.
But we can not controll the grabage collecion. If necessory the jvm invoke to the garbage collecion to maintain the memory management. But we does not give the gaurenty when the jvm invoke the garbage collection. But we can give the request to jvm to invoke the garbage collection by calling gc() that is available in System or Runtime class.
|Shiva said: (Nov 23, 2016)|
|Objects are eligible for GC when they have no references.
Here, Garbage collector never collects an object in the main method and even in method A since there is no object that has no reference.
You can understand that new obj1() has to reference from the array.
|Craig Mautner said: (May 19, 2017)|
|At the completion of methodA() obj2 is eligible for garbage collection. There are no more references to it.|
|Rohit said: (Jun 8, 2019)|
|Option A is correct as the garbage collector will be called in line 9 as the object to which obj1 was referencing, is no longer referenced by anything as now obj2 is referencing the object of obj1.|
Post your comments here:
Email : (optional)
» Your comments will be displayed only after manual approval.