Delete an object created on c++ side


I’m using a function from reflex generated library which returns a pointer to an object which the function has created.
Basically :

A* theFunc() { return new A(); }

Where A is not a TObject (it is actually a std::vector).
I’d like to avoid memory leaks, so how can I delete it from python ? I guess del() won’t be enough to also delete the actual c++ object ?


Hi again,

Mmm, it seems

ROOT.SetOwnership(  obj, True)

just works (obj is given to python and deleted when out of scope). I’ve wrongly assumed obj needed to be a TObject…


you can also set the function theFunc as being one that creates objects for which Python needs to take ownership:theFunc._creates = True