Ownership of non-ROOT objects

Hello all,

After reading about memory handling in PyROOT doc and a few threads here, I still have questions concerning ownership of objects that don’t derive from TObject.
For example, I load my own library in PyROOT through a rootcint generated dictionary. One of my C++ function do this

(I know, this seems stupide :slight_smile: the point is that an object is created inside a function and a pointer given back as a result)

In python this becomes

Now as the object is created in the c++ side, I’m wandering if python will take care of deleting the actual c++ object ? (what is the result of del(a) ? )
If no how can I do it ?

P.A.

Hi,

the best solution I can think of here, is to wrap “myfunc” in a custom python function and use that throughout the python code:def myfunc(): obj = ROOT.myfunc() ROOT.SetOwnership( obj, 1 ) return obj
Note that TObject derivation only gives you communication when the object is deleted. That is to say, if the C++ side deletes the object, it is going to go away, outstanding python refs will be nulled, they do not stop the deletion. So, that does not solve ownership issues, it just prevents segfaults.

Cheers,
Wim