This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 6661
    
    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.
 
wood burning stoves
 
subject: Is this true in Garbage Collection
 
Similar Threads
Tech Word Game
WA #1.....word association
Default Package
Locked Thread
What is the least sexy occupation?