• 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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: 35
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: 62231
193
  • 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.
 
Bartender
Posts: 9559
189
  • 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: 62231
193
  • 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
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!