posted 21 years ago
Question:
If the finalize() method of an object is re-references an object so that it becomes in-eligible for garbage collection
1) The compiler will throw an error.
2) The garbage collector "collects" the object anyway.
3) The garbage collector does not collect the object in the present sweep. But when the object becomes eligible for garbage collection again, its finalize method will not be called by the garbage collector (i.e., if the garbage collector gets a chance to run.). It will simply be garbage collected.
4) The object can never be garbage collected and hence leads to memory-leak. Each time the garbage collector calls finalize before "collecting" the object the object "resurrects" itself.
Answer is 3. Why? I thought it would be 4, since it is re-referencing the object whenever finalize()is called.
The API says that the finalize() is called only once, but what about cases like the above?
Also, can anyone explain the other kinds of common GC implementations, besides "mark and sweep"?
Thanks
Sharda