This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt about garbage collection

 
yuvraj kotegar
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


my question is memory is reclaimed for which object here??

finalize will run for which object?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The garbage collector will call the finalize() method of an object it's about to dispose of. The finalize() you supply here is in the class CheckGC; since no CheckGC objects are ever created, this finalize() will never be called. If the Date class had a finalize() method, then it could be called many times because of all the Date objects being created and discarded.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic