• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

finalize() not called...Garbage collection question

 
Ranch Hand
Posts: 276
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Is there any reason,why finalize() of Hello class is not being called? not even at the termination of the program?!!?!
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JVM never needs to reuse the memory, so the Hello object is never actually collected. The JVM does not collect all objects on exit, either.

You can stick a few calls to System.gc() in there, which may force the Hello object to be collected.
 
Vinoth Kumar Kannan
Ranch Hand
Posts: 276
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ernest Friedman-Hill wrote:The JVM never needs to reuse the memory, so the Hello object is never actually collected. The JVM does not collect all objects on exit, either.


Then what about those things the book says - 'The JVM will collect objects whose references are no longer needed'?!
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..
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

 
reply
    Bookmark Topic Watch Topic
  • New Topic