C++ code crashes when trying to run root files

Dear All,

I keep receiving an error message below when trying to run the attached script. It has worked on a co-worker’s computer but having trouble understanding why I am having these difficulties.

The script in question is an addback script for nuclear structure.

Much appreciated,


fill_hists_new.cpp (16.0 KB)

Processing fill_hists.cpp("root_data_mvmelst_070.bin_tree.root")...
Finished creating histograms
Filling histograms for 1329550 events.

 *** Break *** segmentation violation

There was a crash.
This is the entire stack trace of all threads:
#0  0x00007fcb820ea45a in __GI___wait4 (pid=3970, stat_loc=stat_loc
entry=0x7ffde4f78358, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:30
#1  0x00007fcb820ea41b in __GI___waitpid (pid=<optimized out>, stat_loc=stat_loc
entry=0x7ffde4f78358, options=options
entry=0) at ./posix/waitpid.c:38
#2  0x00007fcb82050bcb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:171
#3  0x00007fcb82b17494 in TUnixSystem::StackTrace() () from /usr/local/lib/libCore.so
#4  0x00007fcb82b14795 in TUnixSystem::DispatchSignals(ESignals) () from /usr/local/lib/libCore.so
#5  <signal handler called>
#6  0x00007fcb81a9f546 in ?? ()
#7  0x0000000000000000 in ?? ()

The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum https://root.cern.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern.ch/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
#6  0x00007fcb81a9f546 in ?? ()
#7  0x0000000000000000 in ?? ()

ROOT Version: 6.24/06
Platform: Ubuntu

Hi @Xavier_James!

Which ROOT version does your coworker use? You’re using 6.24/06, which is already a few years old. Could it be that the problem went away with newer ROOT versions? The most recent one is 6.28/06.

Besides that, I can’t give you any advice unfortunately. The stack trace is not very telling. If you want us to debug further, can you please share the "root_data_mvmelst_070.bin_tree.root" file so we can try to find the error?


Hi @jonas ,

We are both using the same version of ROOT. I will attach the file in this message. Thank you!

Unfortunately, it is a couple gigs and will not allow me to attach it to this message.

Okay, that’s a problem then. Maybe you find another way of sharing the file?

But if it’s so much data maybe that could be a hint to the problem. Is it possible that the memory usage grows so large that this causes a crash, and you maybe have less RAM than your colleague? Did you monitor the memory usage with top or some other system tool while the ROOT macro is running?

Dear @Xavier_James ,

On top of what Jonas already suggested and his comments, which are all correct and on point, may I also strongly suggest you to revisit your code in order to avoid all the dynamic allocations with no memory management? That means, every time there is a call to new in your program there should be a corresponding delete call. Currently, your program has zero delete. Since this approach is quite cumbersome, you should simply avoid creating objects on the heap whenever possible and just declare them on the stack (e.g. TH1D myHisto; instead of auto myHisto = new TH1D()). Or, if you really need to create objects on the heap, wrap them in std::unique_ptr.


The data files are supposed to be a few gigs since it contains experimental data. I have monitored the memory usage and have been editing line by line.

Thank you! I will try that and see if that will work.