| Author |
Garbage Collection: Query.
|
Monu Tripathi
Rancher
Joined: Oct 12, 2008
Posts: 1365
|
|
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] | [My Blog] | [Samuh Varta]
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
|
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: 1365
|
|
Thanks CR for your reply..
Will the class be "definitely" unloaded after the application terminates?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
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: 1365
|
|
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: 32708
|
|
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: 1365
|
|
Perfect!
Thanks!
|
 |
 |
|
|
subject: Garbage Collection: Query.
|
|
|