4.5. 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.

4.5.1. ThreadSafeFinalizer

4.5.2. Finalizer

4.5.3. Py4J Finalizer Functions

Questions/Feedback?