File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Is this true in Garbage Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Is this true in Garbage Collection" Watch "Is this true in Garbage Collection" New topic
Author

Is this true in Garbage Collection

Sreeraj Harilal
Ranch Hand

Joined: May 09, 2006
Posts: 45
Can we use a Garbage collected object again?


SCJP 5.0<br />SCWCD 1.4<br />SCBCD 1.3<br />SCEA part 1
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

If you override the finalize method and some how save the object from being garbage collected ( eg: you save the reference to that object ) then the object will not be garbage collected. Once an object is garbage collected it cannot be reached because it has been removed from memory. An object is GC ed only when no reference can reach it , or when an island of isolation occurs.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
In addition :

finalize() method will be called only once in the life time of an object. So even if you override the finalize method and save the object from being garbage collected, finalize() will not be called when it's again eligible for GC.


Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Sreeraj Harilal
Ranch Hand

Joined: May 09, 2006
Posts: 45
I read from somewhere that we can use an object after its finalize method called.
I think finalize is called only before the GC is taken place. right?
Please give me an explanation.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Is this true in Garbage Collection