Vinoth Kumar Kannan wrote:
Then what about those things the book says - 'The JVM will collect objects whose references are no longer needed'?!
If you have a book that says precisely that, it's wrong. It would be correct to say "The JVM may collect unreferenced objects when the memory they consume is needed for reuse."
Even on terminating,if JVM doesn't collect objects then...at some point of time,u'll have no free space at all,right?! I dunno whether i'm making sense myself... Just confused..
When a process like the JVM exits, the operating system (Windows, Linux, etc) will reuse all of its memory. There's no need for the JVM to collect the individual objects -- the whole process gets "collected" by the operating system.