It's not a secret anymore!
The moose likes Beginning Java and the fly likes Garbage collection will be triggered and finalize method will be called ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Garbage collection will be triggered and finalize method will be called ?" Watch "Garbage collection will be triggered and finalize method will be called ?" New topic
Author

Garbage collection will be triggered and finalize method will be called ?

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 580
I have some code in finalize method and assume that the object always in use and never become eligible for garbage collection ,now if the JVM closes then what what wll happen
Garbage collection will be triggered and finalize method will be called ?
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 4087
    
  18

No. When the JVM closes, that's that. Nothing happens any more.


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20128
    
  30

You can try to use Runtime.getRumtime().addShutdownHook(...) but that's also not guaranteed to run if the JVM exits abruptly.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage collection will be triggered and finalize method will be called ?
 
It's not a secret anymore!