• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 5599
55
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. When the JVM closes, that's that. Nothing happens any more.
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try to use Runtime.getRumtime().addShutdownHook(...) but that's also not guaranteed to run if the JVM exits abruptly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic