Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What is the case in which makes " finalize() " is run ?  RSS feed

 
Gheyath Nasani
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the case in which makes " finalize() "  is run ?  and is there an example when " finalize() " is run ?
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The finalize() method is called by the garbage collector, after the GC has determined that the object is unreachable, right before the object is collected. And of course, if the finalize() method makes the object reachable, then the object will not be collected.

Additionally, the GC will, at most, call the finalize method once.

Henry
 
Campbell Ritchie
Marshal
Posts: 55700
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Find a copy of Effective Java by Joshua Bloch. It used to be possible to find a .pdf of the 3rd chapter as a sample chapter free of charge. That will tell you about finalize(). Bloch recommends you don't use it for most applications.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!