I try my best to find memory leaks in a very important module in our project and get a code snippet as follows:
PyObject* python_func( const char* str ) { .......................... boost::python::list obj; obj.append(str); obj.ptr()->ob_refcnt++;
I got confused on this line: obj.ptr()->ob_refcnt++;
I think that ob_refcnt is supported by python inside gc, we cannot use it, so obviously this will lead to a memory leak, on the other hand, obj is going to leave its scope, I am not sure that boost :: python :: list deconstructor will reduce ob_refcnt, if true, delete this line, the obj hold resource will be released, which will lead to failure.
So my question is: is obj.ptr()->ob_refcnt++; and why?
source share