my dog learned polymorphism
The moose likes Beginning Java and the fly likes Doubt about garbage collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Doubt about garbage collection" Watch "Doubt about garbage collection" New topic

Doubt about garbage collection

yuvraj kotegar
Ranch Hand

Joined: Jul 31, 2008
Posts: 120

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

finalize will run for which object?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

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.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Doubt about garbage collection
It's not a secret anymore!