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.
The moose likes Beginning Java and the fly likes Garbage Collection Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Garbage Collection Doubt" Watch "Garbage Collection Doubt" New topic
Author

Garbage Collection Doubt

aresh babu
Ranch Hand

Joined: Aug 31, 2008
Posts: 65
How can we stop garbage collecting a user define object permanantly without assigning the references once again to that object?



Thanks in advance

Francisco Montes
Ranch Hand

Joined: Sep 30, 2009
Posts: 30
My understanding:

An object is eligible for garbage collection as soon as there is no references to it from any live thread.

So, unless you override the finally method of that object and make a reference variable (in a live thread) point to it... it may get garbage collected.


SCJP 1.6
Embla Tingeling
Ranch Hand

Joined: Oct 22, 2009
Posts: 237
aresh babu wrote:How can we stop garbage collecting a user define object permanantly without assigning the references once again to that object?


You assign the object reference to a variable that's static and final, like

static final Object o = new Objcet(); // object will never be GCed
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44550
    
  34
Francisco Montes wrote: . . . So, unless you override the finally method of that object and make a reference variable (in a live thread) point to it... it may get garbage collected.
By a "finally method," do you mean a finally block or a final reference?
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19747
    
  10

Campbell Ritchie wrote:
Francisco Montes wrote: . . . So, unless you override the finally method of that object and make a reference variable (in a live thread) point to it... it may get garbage collected.
By a "finally method," do you mean a finally block or a final reference?

I'm guessing that Francisco meant the "finalize" method.
Francisco Montes
Ranch Hand

Joined: Sep 30, 2009
Posts: 30
True, I meant "finalize" (oops). Thanks Paul. :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage Collection Doubt
 
It's not a secret anymore!