User Tools

Site Tools


root:ownershippyroot

Ownership in PyROOT

As python has a garbage collector, you have to make sure to pass on all objects that you want to keep. For example canvases.

The following macro will produce 10 empty canvases and delete them in the end.

from ROOT import *
import ROOT
 
for i in range(0,10):
    canv = TCanvas("canv"+str(i))

To avoid this, you can tell python not to take ownership of these objects:

from ROOT import *
import ROOT
 
for i in range(0,10):
    canv = TCanvas("canv"+str(i))
    ROOT.SetOwnership(canv, False)

will give you 10 canvases after having executed this script.

root/ownershippyroot.txt · Last modified: 2011/06/18 12:13 by decianm