py4j.finalizer
— Py4J Finalizer API¶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.