ROOT Version: 6.18/04
Platform: CentOS 7.6
Compiler: gcc 9.2.0
Hello,
I am experience a quite strange issue that is having me scratch my head. It seems quite simple: I open a TFile, extract an object, read some numbers, and then close the TFile. When I do this in a loop, I see the memory consumption increasing continuously. I have traced it to this very specific block of code by including / removing it in the running loop.
The code looks like this:
template <typename T>
T *fetch(TFile *f, const std::string &nm, T *def = NULL, bool clone = true) {
if (f == NULL || f->IsZombie()) {
return def;
}
TObject *obj(0x0);
if (clone) {
gROOT->cd();
obj = f->Get(nm.c_str())->Clone((nm + "_clone").c_str());
} else {
obj = f->Get(nm.c_str());
}
if (obj != NULL) {
return dynamic_cast<T *>(obj);
} else {
return def;
}
}
for(unsigned i = 0; i < 10000; ++i) {
TFile* f = TFile::Open("/path/to/file.root", "read");
TGraph* g = fetch<TGraph>(f, "graph", NULL, false);
int n = g->GetN();
delete f;
}
Perhaps you might object to the delete f, but I tried f->Close(); and see the same thing: with every loop, memory consumption increases.