Re: Creating C++ objects from PyRoot/GaudiPython vs. from C++

From: <wlavrijsen_at_lbl.gov>
Date: Fri, 25 Feb 2011 10:23:02 -0800


Brett,

> What I suspect is that when I create a C++ object from Python, Python
> marks it as owned-by-Python

yes.

> and takes over explicit memory management
> which defeats the reference-counting that is supposed to be done on the
> C++ side.

Well, the interface is not aware that the C++ side is doing reference counting on the C++ side, as there is nothing there to tell it so.

> If this is the case, is there some way to tell Python not to memory
> manage the underlying object (or better, to participate in the C++-side
> reference counting)?

A couple. If, as I understand your message, all these particular C++ objects that you have participate in the C++-side reference counting and should never be managed by python, then do:

     from GaudiPython import gbl
     gbl.DayaBay.__init__._creates = False
     ud = gbl.DayaBay.UserDataHeader()

Additional options are to tell the function that stores the object into the store that it should take ownership rights, or setting ownership on the python object directly.

Note that GaudiPython has a different memory policy by default then does ROOT.

Best regards,

            Wim

-- 
WLavrijsen_at_lbl.gov    --    +1 (510) 486 6411    --    www.lavrijsen.net
Received on Fri Feb 25 2011 - 19:23:15 CET

This archive was generated by hypermail 2.2.0 : Fri Feb 25 2011 - 23:50:01 CET