Refinement of finalize () method in class Object

It would be useful if someone could correctly clarify 2 points from the javadoc of the finalize () method in the Object class:

1. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked.

What is the meaning of user-visible synchronization? Is there any other synchronization besides the "user visible"?

2. The finalize method is never invoked more than once by a Java virtual machine for any given object.

In this case, the JVM must support the unique identification of each object ever created and the information that the finalize method called. Will it not ultimately grow outside the region in which it is stored?

+4
source share
3 answers

What is the meaning of user-visible synchronization?

Block you canc ccess from Java code.

Is there any other synchronization besides the "user visible"?

, JVM .

JVM , - , , finalize.

, . . , , .

, ?

.

Java

+2

, (!) finalize(). , .

+1

" " ? , " "?

" ", , , . JVM , .

JVM , - , , finalize. , ?

No - this is because as soon as the JVM calls finalize()- in the end the object will be gc'd.

+1
source

Source: https://habr.com/ru/post/1538541/


All Articles