I noticed that when creating a PyObject in Java using method call(...) or callMethod(...), it lives forever....
In method PyLib_CallAndReturnObject, an object is first created
(pyReturnValue = PyObject_CallObject), then its reference is incremented
(Py_INCREF (pyReturnValue)), and then the reference is incremented again in the PyObject constructor in Java:
PyObject(long pointer) {
if (pointer == 0) {
throw new IllegalArgumentException("pointer == 0");
}
PyLib.incRef(pointer);
this.pointer = pointer;
}
However, I found only one case, when the counter decrements - the PyObject's finalize(). Therefore, the object continues to exist with two references, and a memory leak occurs.
Is this a bug, or am I misunderstanding something? (sorry, this is my first expirience with Python C API)
Hello guys,
I noticed that when creating a PyObject in Java using method
call(...)
orcallMethod(...)
, it lives forever....In method
PyLib_CallAndReturnObject
, an object is first created (pyReturnValue = PyObject_CallObject
), then its reference is incremented (Py_INCREF (pyReturnValue)
), and then the reference is incremented again in the PyObject constructor in Java:However, I found only one case, when the counter decrements - the PyObject's
finalize()
. Therefore, the object continues to exist with two references, and a memory leak occurs. Is this a bug, or am I misunderstanding something? (sorry, this is my first expirience with Python C API)