Finding memory leaks

Dear ROOTers,

I am currently trying to locate a memory leak. My code is written in C++, but I call it from PyROOT, which makes it hard to use with rootn.exe. I was wondering if there might be any advice on how to go about finding the problem.

At the very least, a fine-grained memory usage statistic would be useful. Currently the best I can find are gSystem.GetProcInfo + fMemResident, but this gives me the information in kilobytes, as does statm.

More useful still would be a way of knowing all mallocs/frees that are performed, and where they came from. I tried valgrind but it spat out an awful lot of errors that were not to do with my code.

Any help is appreciated.

Regards,

  • Peter

Hi,

you can use valgrind’s massif tool, or ROOT’s object statistics facility; see “Tracking Memory Leaks” in the Users Guide.

Cheers, Axel.

Neat, the object table is exactly the kind of thing I was looking for. Why is there no way to access the table programmatically? just printing a gigantic table to the screen is not very useful.

Is there a simple way to get that information programmatically? even if it was in a string that would be fine - I’d rather not pipe it to a file.

Regards,

  • Peter

You can access the TObjectTable::Api or the TClass API.
See how to do it in TObjectTable::InstanceStatistics

Rene

Ah. I had an assumption about how TObjectTable worked. I didn’t realise I could access most of the information through functions such as gROOT->GetListOfClasses() and TClass::GetInstanceCount(). I even looked at the TObjectTable code - obviously not closely enough.

I can’t see any way to access fTable though, or the contents of it, without calling Print(“all”) - is there a way to access this information programmatically?

Regards,

  • Peter

I will add a getter function for fTable, but this should be very rarely required to find leaks (I mean Print(“all”))

Rene