From one article

The collector will clear the finalized object in two steps: the first will execute finalize, and the second will build.

And so questions

  1. When the collector encounters a finalized object, it first sends it to the queue. And the code in the finalize method is already in the queue. When the method is executed, it will be available to the collector and destroyed during the next assembly. I understood correctly?
  2. Stop the world acts on the stream Finalizer?
  • Thanks for the normal design of the question :) - Pavel Mayorov
  • Thank you for the good answer) - T. Kudaibergen

1 answer 1

Yes, you are right - after the finalize() method is executed, the object must be reassembled by the garbage collector (and this is considered a serious problem for the finalize() method - it prevents the garbage collector from freeing memory).

By the way, an object will not necessarily be available for assembly immediately - the finalize() method can save an object reference somewhere. This situation is called the “rebirth” of the object and, generally speaking, is considered anti-pattern. The main problem with this trick is that the object can only be “revived” once.


Stop the world is definitely affecting the Finalizer thread, because it’s the same thread as everyone else.