Questions tagged [finalize]

A finalize() is a special method in an object-oriented language that is executed when an object is garbage collected.

A finalize(), or a finalizer, is a special method in an object-oriented language that is executed when an object is garbage collected.

Java Documentation (Javadoc) defines the moment when the finalize() is invoked as:

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

However, this may never happen in the life of a program if the object is always accessible. Due to the lack of programmer control over their execution, it is usually recommended to avoid finalizers for any but the most trivial operations.

Starting Java9. finalize() method has been officially deprecated. javadoc for Java9's java.lang.Object finalize()

228 questions
-1
votes
5 answers

Difference between final keyword, finally block and finalized method in java throught one good example

Often these keywords confuse me. Can any one tell me exactly what the difference between them is?
Mitul Maheshwari
  • 2,647
  • 4
  • 24
  • 38
-2
votes
1 answer

Java Object.finalize() vs. C# IDisposable

I have extensive Java experience and know why finalize() is scheduled for a removal soon. On the other hand, my knowledge about C# is skin-deep - I am more or less aware about what features it offers on the abstract level, but no real experience to…
Turin
  • 2,208
  • 15
  • 23
-2
votes
1 answer

Object Creation in java and finalize

class FDemo { int x; FDemo(int i) { x = i; } protected void finalize() { System.out.println("Finalizing " + x); } void generator(int i) { FDemo o = new FDemo(i); …
Sunil
  • 29
  • 7
1 2 3
15
16