TTree and Smart Pointers

Hello Everyone,

I’m getting *** Break *** segmentation violation when using unique_ptr on TTree:

root [0] auto theTree = std::make_unique<TTree>("myTree","MyTestTree")
root [1] .q

Is this a glitch?. It doesn’t happen the same if I use make_shared though.

Thanks a lot

ROOT Version: v6-14-04
Platform: linuxx8664gcc

Hi Andres,
as per ROOT’s historical ownership rules, a TTree created like that will belong to the current gDirectory. At teardown, both the unique_ptr and the gDirectory will delete the TTree, causing the crash.

There is an easy solution in v6.14 though, that was put in place exactly to avoid these kind of issues: you can tell the TTree to not register in any TDirectory, like this:

auto theTree = std::make_unique<TTree>("myTree","MyTestTree", /*splitlevel=*/99, /*dir=*/nullptr);

where splitlevel 99 is simply the default value.


1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.