Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
jacob deiter
Ranch Hand
Posts: 583
  • 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: 5387
52
  • 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: 20495
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