This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

object’s Finalize() method Invoke  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When will an object’s Finalize() method Invoke?
 
Ranch Hand
Posts: 44
1
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the stackoverflow question. I think it will be helpful for you.
 
Ranch Hand
Posts: 99
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch!  
 
Marshal
Posts: 63314
205
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch again

Please search CodeRanch about finalize() (not Finalize()). You will find that method is deprecated; you should no longer use it. This discussion was the most useful thing I found when I searched. It also gives you hints about when finalize() runs.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An object’s finalize() method can’t invoke by the garbage collector whereas the thing continues to be reachable. However, an object’s finalize() method could also invoke by different objects.
 
Saloon Keeper
Posts: 9799
197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be wary that even though the garbage collector only calls the finalize() method once after the object becomes phantom reachable, the finalize() method can "resurrect" the garbage collected object by strongly referring to it in a field.

When the resurrected object becomes phantom reachable again, the finalize() method will NOT be called a second time. See this discussion: https://coderanch.com/t/555619/java/Phantom-Reference

The use of the finalize() method has been deprecated. Use a Cleaner to perform cleanup when an object is garbage collected.
 
Campbell Ritchie
Marshal
Posts: 63314
205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

anjita agrawal wrote:. . . . However, an object’s finalize() method could also invoke by different objects.

That should be regarded as permissible only under the heading of . . .

I only wanted to see what happens if . . .

. . . and not on real life.

And, welcome to the Ranch
 
yeah, but ... what would PIE do? Especially concerning this tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!