• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collection: Query.

 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50189
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks CR for your reply..

Will the class be "definitely" unloaded after the application terminates?
 
Campbell Ritchie
Sheriff
Pie
Posts: 50189
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found this article on JavaWorld on .. Java Memory Management.. maybe this would help
 
Campbell Ritchie
Sheriff
Pie
Posts: 50189
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mudit Srivastava wrote:Found this article . . .
Good article.
 
Brian Legg
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perfect!

Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic