The py4j.finalizer module contains global classes that enables the registration of finalizers, i.e., weak reference callbacks. This module is used by Py4J to register a finalizer for each JavaObject instance: once there is no more reference to a JavaObject instance on the Python side, the finalizer sends a message to the JVM to remove the reference from the Gateway to prevent memory leak.
The py4j.finalizer module is necessary because JavaObject instances have circular references with JavaMethods and hence, they cannot keep their own finalizer.
A ThreadSafeFinalizer is a global class used to register weak reference finalizers (i.e., a weak reference with a callback).
This class is useful when one wants to register a finalizer of an object with circular references. The finalizer of an object with circular references might never be called if the object’s finalizer is kept by the same object.
For example, if object A refers to B and B refers to A, A should not keep a weak reference to itself.
ThreadSafeFinalizer is thread-safe and uses reentrant lock on each operation.
Registers a finalizer with an id.
Parameters: |
|
---|
Removes all registered finalizers.
Parameters: |
|
---|
Removes a finalizer associated with this id.
Parameters: |
|
---|
A Finalizer is a global class used to register weak reference finalizers (i.e., a weak reference with a callback).
This class is useful when one wants to register a finalizer of an object with circular references. The finalizer of an object with circular references might never be called if the object’s finalizer is kept by the same object.
For example, if object A refers to B and B refers to A, A should not keep a weak reference to itself.
Finalizer is not thread-safe and should only be used by single-threaded programs.
Registers a finalizer with an id.
Parameters: |
|
---|
Removes all registered finalizers.
Parameters: |
|
---|
Removes a finalizer associated with this id.
Parameters: |
|
---|
Removes all registered finalizers in ThreadSafeFinalizer and Finalizer.
Parameters: |
|
---|