This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I manage to get it wrong almost always in the mocks. I have read this from mughal and Marcus Green tutorial. But I am unable to solve questions based on this topic. Can somebody guide me how to approach this topic and questions based on it confidently? TIA, - Manish
General guide lines: G.C. cannot be forced only requested. The G.C. doens�t prevent an OutOfMemoryError . The g.c. of an object is not guaranted. The finalize method of an object will be only called (automatically) if the g.c. is running. It is not guaranted its execution though. However it is guaranted that if executed, it will be executed only once for an object, just before its memory is reclaimed. Also it is guaranted that if an object is recycled its finalized method has already been executed. An object is eligable for g.c. if it is unreachable by all the reachable objects. This means that A is eligable for g.c. if there aren't any references to it, except from, for instance, from B object which is also unreachable. Be careful with aliasing the objects. If two or more variables points to the same object, typical mock exams try to confuse by only seeting to null, or copying new values to them, to only some of the variables. Just keep posting the Ranch the questions you find difficult in the mocks [ March 17, 2002: Message edited by: Jose Botella ] [ March 17, 2002: Message edited by: Jose Botella ]
Thanks a lot, both of you Also, I found this approach very useful - 1)Draw the object and references pointing to it on paper 2) Modify the references as per the code and examine if the object still has any valid ref., if not it *is* eligible for GC. I managed to get both the GC questions correct in the last mock using this approach. Just thought I'll share it. Regards, - Manish