HOW TO AVOID ANY OBJ. FROM BEING GARBAGE COLLECTED
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Trupti_Mehta
Posted On:   Thursday, December 12, 2002 08:23 PM



Hi,


I want some objects of my application to never get
Garbage Collected until the prg. stops. How can I
avoid/tell GC to not to collect the obj regardless of the
usage of the obj.


Is their any solution to solve this problem? If so,
from which version of JDK was this available.


Thanks


Trupti

Re: HOW TO AVOID ANY OBJ. FROM BEING GARBAGE COLLECTED

Posted By:   Joe_Cheng  
Posted On:   Friday, December 13, 2002 07:45 PM

Any reachable reference to the object will keep it from being garbage collected. If there is no other good place to keep it, you can probably just make it reachable from a static member.

Which begs another question... under what conditions can a class be garbage collected?

Anyway Trupti, why are you worrying about this? If an object is unreachable yet you want to make sure it doesn't get collected, you probably need to refactor your design. If you're just asking if reachable objects will ever be gc'd, the answer is no.

Re: HOW TO AVOID ANY OBJ. FROM BEING GARBAGE COLLECTED

Posted By:   Gautam_Marwaha  
Posted On:   Thursday, December 12, 2002 11:15 PM

maintain a reference to that object and it will not become a candidate for garbage collection
About | Sitemap | Contact