Saturday, 10 August 2013

using boost::python::list as return value need increase ob_refcnt?

using boost::python::list as return value need increase ob_refcnt?

I am trying my best to find memoryleaks in a very important module in our
project and got a code sinpet like this:
PyObject* python_func( const char* str ) { ..........................
boost::python::list obj;
obj.append(str);
obj.ptr()->ob_refcnt++; //this is necessary??
return obj.ptr();
}
I am confusing about this line "obj.ptr()->ob_refcnt++;".
i think ob_refcnt is maintained by python internally for gc, we can't
operate it so obviously casuse this will lead to memory leaks, on the
other hander, obj is going to leave its scope, i am not sure if
boost::python::list deconstructor will decrease ob_refcnt, if that true,
remove that line,the resource obj hold would be released, that will lead
to crash
So my question is "does obj.ptr()->ob_refcnt++; is necessary? and why?"

No comments:

Post a Comment