[det]py_free(+Obj)Immediately free (decrement the reference count) for the Python object Obj.
Further reference to Obj using e.g., py_call/2
or
py_free/1 raises an existence_error
.
Note that by decrementing the reference count, we make the reference
invalid from Prolog. This may not actually delete the object because the
object may have references inside Python.
Prolog references to Python objects are subject to atom garbage
collection and thus normally do not need to be freed explicitly.
- Compatibility
- PIP. The SWI-Prolog implementation is safe and normally reclaiming
Python object can be left to the garbage collector. Portable
applications may not assume garbage collection of Python objects and
must ensure to call py_free/1
exactly once on any Python object reference. Not calling py_free/1
leaks the Python object. Calling it twice may lead to undefined
behavior.