I am writing an online monitor GUI in which a set of TH2’s are updated and re-drawn every 10 seconds. While running top alongside my GUI, I noticed that the memory footprint increases by about 10MB upon each re-drawing iteration.
Is there a way to prevent this? A stripped-down version of my code is attached.
memleak.C (9.85 KB)
I do not see any place in your code where you destroy the many TH1, TH2 histograms.
Do you mean destroy the objects themselves, or simply remove them from the canvas somehow? I’d rather avoid the former, and I’ve tried using TCanvas::Clear() to achieve the latter with, negative results.
I find the code leaks, even if UpdateMethod() is changed to:
void *MyMainFrame::UpdateMethod(void *arg)
… and it does not leak if updatethread->Run() is not called.
So something interesting is going on here?
static Long_t oldMem = 0;
gSystem->GetProcInfo( &pi );
Long_t newMem = pi.fMemResident;
cout << "Mem delta: " << (newMem - oldMem) << endl;
oldMem = newMem;
pwaller, I just noticed that myself, this morning. The memory increases every time the thread is called, regardless of whether or not the histogram functions were commented out.