permaculture playing cards*
The moose likes Beginning Java and the fly likes Garbage Collection: Query. 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 » Java » Beginning Java
Bookmark "Garbage Collection: Query." Watch "Garbage Collection: Query." New topic
Author

Garbage Collection: Query.

Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369
    
    1

When does an Object of class implementing Singleton Pattern become eligible for garbage collection, assuming that it has been instantiated once?

I believe it remains in memory for a much longer time(does it actually remain until the class is unloaded?) and therefore, developers are asked to refrain from using such patterns when developing applications for constrained devices(e.g cell phones etc.)

Please clarify...

Thanks.


[List of FAQs] | [Android FAQ] | [Samuh Varta]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
I think you are correct. If you have the usual pattern withthen I would expect the instance to remain accessible from when it is instantiated until whenever the class is unloaded.
Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369
    
    1

Thanks CR for your reply..

Will the class be "definitely" unloaded after the application terminates?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
You're welcome

if "application terminates" means the JVM closes down, then yes the class will be unloaded. If it means anything earlier, don't know. Sorry.
Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369
    
    1

Hmm..I would like to read up on - what happens in memory when a JVM is started, java class is loaded/ unloaded, objects created etc. Do you have any links or pointers that can help me with the above?

Thanks again..
Mudit Srivastava
Ranch Hand

Joined: Apr 30, 2007
Posts: 38
Found this article on JavaWorld on .. Java Memory Management.. maybe this would help
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Mudit Srivastava wrote:Found this article . . .
Good article.
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
This isn't related to garbage collection but here's an article that has some great insite on the inner workings of a Singleton.

Singleton

SCJA
~Currently preparing for SCJP6
Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369
    
    1

Perfect!

Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage Collection: Query.