The object is eligible for garbage collection only if there is no strong reference to the object. An exception to this is island of references(where all objects point to each other).And you should never write your significant code in the object's finalise method because you can never be very sure that it will run. Finalise method runs only once in the life-time of an object. So even if you re-initialise an object in its finalize code, it can become eligible for garbage collection(if there is no strong reference to the object) and its finalise method won't be called again.Buddhadev Wrote:the logic behind the gerbage collection is that , the JVM look for the object reference that are not in used and then the JVM mark them for gerbage collection and remove them for better memory management.
So if we want a object that should not subject to gerbage collection, then we have to use the finalized method and re initiate the object which we don't want to be gerbage collected.
because when first time the JVM mark the object as aligible for gerbage collection, it will first call the finalized method og that class. and as we re instanciate the object in the finalized method the object will not subject to gerbage collection.
Harish Wrote: How we can create objects that are not subject to garbage collection?
Plz answer me soon...