Corey Reed
2013-08-02 21:38:30 UTC
Hi,
I believe I've tracked a memory leak in a complicated script of mine to
the following effect: after using ROOT.TFile.Open to open a file, the
file does not get destructed when all python references to it are gone.
I'm hoping someone can explain this to me.
Take the following simple python script, using ROOT 5.34.03:
---
import ROOT,gc,objgraph
f = ROOT.TFile.Open("test.root","recreate")
print objgraph.by_type('TFile')
del f
gc.collect()
#f.IsA().Destructor(f)
print objgraph.by_type('TFile')
ROOT.gROOT.GetListOfFiles().ls()
---
The resulting output shows:
[<ROOT.TFile object ("test.root") at 0x9597dd8>]
[]
OBJ: TList Files Doubly linked list : 0
TFile** test.root
TFile* test.root
(Using gObjectTable also shows the TFile is still around).
The file is still open! Why?? There are no more python references to the
file, as evidenced by the empty array printed by objgraph.
Changing to ROOT.kMemoryStrict has no affect on this behavior.
Alternatively, calling the destructor explicitly with the macro:
---
import ROOT,gc,objgraph
f = ROOT.TFile.Open("test.root","recreate")
print objgraph.by_type('TFile')
#del f
#gc.collect()
f.IsA().Destructor(f)
print objgraph.by_type('TFile')
ROOT.gROOT.GetListOfFiles().ls()
---
Gives the expected result:
[<ROOT.TFile object ("test.root") at 0xa71bde8>]
[]
OBJ: TList Files Doubly linked list : 0
- Corey
I believe I've tracked a memory leak in a complicated script of mine to
the following effect: after using ROOT.TFile.Open to open a file, the
file does not get destructed when all python references to it are gone.
I'm hoping someone can explain this to me.
Take the following simple python script, using ROOT 5.34.03:
---
import ROOT,gc,objgraph
f = ROOT.TFile.Open("test.root","recreate")
print objgraph.by_type('TFile')
del f
gc.collect()
#f.IsA().Destructor(f)
print objgraph.by_type('TFile')
ROOT.gROOT.GetListOfFiles().ls()
---
The resulting output shows:
[<ROOT.TFile object ("test.root") at 0x9597dd8>]
[]
OBJ: TList Files Doubly linked list : 0
TFile** test.root
TFile* test.root
(Using gObjectTable also shows the TFile is still around).
The file is still open! Why?? There are no more python references to the
file, as evidenced by the empty array printed by objgraph.
Changing to ROOT.kMemoryStrict has no affect on this behavior.
Alternatively, calling the destructor explicitly with the macro:
---
import ROOT,gc,objgraph
f = ROOT.TFile.Open("test.root","recreate")
print objgraph.by_type('TFile')
#del f
#gc.collect()
f.IsA().Destructor(f)
print objgraph.by_type('TFile')
ROOT.gROOT.GetListOfFiles().ls()
---
Gives the expected result:
[<ROOT.TFile object ("test.root") at 0xa71bde8>]
[]
OBJ: TList Files Doubly linked list : 0
- Corey