when i create a object( say a hashmap object) , is that object lifecycle limited to the method call or is this object available for garbage collection. another doubt which springs into my mind...what all objects are really eligible for garbage collection?
It NEVER forces garbage collection. I'd have thought this myth would be dispelled by now? Clearly, it is still floating around [ October 22, 2004: Message edited by: Tony Morris ]
Daniel Salomons
Greenhorn
Joined: Oct 07, 2004
Posts: 5
posted
0
The javadoc says this about System.gc():
gc
public static void gc()
Runs the garbage collector.
Calling the gc method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. When control returns from the method call, the Java Virtual Machine has made a best effort to reclaim space from all discarded objects.
To me, it seems that all objects are removed as far as possible by the JVM. If you are complaining that this is not so, maybe you have some references that are accessible for the JVM, but have become invisble to you. ;-) Daniel SCJP 1.4
Tony Morris
Ranch Hand
Joined: Sep 24, 2003
Posts: 1608
posted
0
To me, it seems that all objects are removed as far as possible by the JVM.
You missed the word 'suggests'. In practice, it very seldom works. Also in practice, calling it is almost always a bad idea.
I can't believe I'm saying this again! I've seen this thread of communication hundreds of times!
Corey McGlone
Ranch Hand
Joined: Dec 20, 2001
Posts: 3271
posted
0
Here's a link to an article regarding garbage collection. Maybe it will help answer some of your questions.
One thing to keep in mind - when it comes to garbage collection, there are virtually no guarantees. You never know when or if garbage collection will take place. You can "suggest" that it take place, but you can't force it to.