# Valgrind and ROOT

**URL:** <https://root-forum.cern.ch/t/valgrind-and-root/28506>\
**Category:** Howto\
**Created:** [March 29, 2018, 1:40pm UTC](https://root-forum.cern.ch/t/valgrind-and-root/28506 "2018-03-29T13:40:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [March 29, 2018, 1:40pm UTC](https://root-forum.cern.ch/t/valgrind-and-root/28506/1 "2018-03-29T13:40:31Z")

</div>

### Memory Checks

ROOT triggers a couple of [valgrind](http://valgrind.org/) reports that are intentional (see below if you care why). To suppress those use the following invocation:

```bash
valgrind --num-callers=30 --suppressions=$ROOTSYS/etc/valgrind-root.supp root.exe -l -b -q myscript.C

```

Note: yes, really `root.exe`, even on Linux and macOS!

### Threading Checks

tbb (used by ROOT) is confusing helgrind; this is a [known issue](https://software.intel.com/en-us/forums/intel-threading-building-blocks/topic/295293). To suppress these known false-positives, please use

```auto
valgrind --tool=helgrind --suppressions=$ROOTSYS/etc/helgrind-root.supp ./myMultithreadedProgram

```

Please run valgrind on `root.exe`, also on Linux: `root` is a tiny wrapper around `root.exe` and `valgrind` will not report anything on `root`. The same options can of course be used when `valgrind`ing your own programs!

### CPU Profiling

You can invoke `valgrind --tool=callgrind --fn-skip=_dl_runtime_resolve_avx root.exe -l -b -q myScript.C+` to see where the time is spent. The `--fn-skip` argument avoids circles (A calls B calls C calls A) that are synthetic due to shared library symbol lookup; the actual function name might differ, its `_avx` version is common on current Intel architectures.

### Why suppressions?

TObject-derived classes are tagging heap allocated memory to determine heap versus stack allocations, which triggers reports in valgrind. cling tries to read from pointers even if the memory they point to hasn’t been initialized, to report invalid pointers instead of crashing. And lastly, ROOT’s meta-classes (`TClass` and friends) are providing data even at process shutdown time, when ROOT writes `TFile`s that are still open. To “survive” this phase, ROOT intentionally keeps meta objects alive. This is not a problem because we simply delay the deletion of these objects until the _real_ end of the program: the kernel will take care of it.
