Problem deleting TList of TCanvases

Dear support,

in my case in one root session i am creating and deleting TList of TCanvas, TH1, THStack and when i try to use TTList::Delete() from time to time i get errors like this

#8  0x000000002ee27da0 in ?? ()                                                                                                                                                                                                                                                                                                                                                                                                             
#9  0x00007fcec3fe6159 in TList::RecursiveRemove(TObject*) () from /usr/lib64/root/libCore.so.6.38                                                                                                                                                                                                                                                                                                                                          
#10 0x00007fcec31e7c03 in TTree::RecursiveRemove(TObject*) () from /usr/lib64/root/libTree.so.6.38                                                                                                                                                                                                                                                                                                                                          
#11 0x00007fcec3fd9df5 in THashList::RecursiveRemove(TObject*) () from /usr/lib64/root/libCore.so.6.38                                                                                                                                                                                                                                                                                                                                      
#12 0x00007fcec3fe6435 in TList::RecursiveRemove(TObject*) () from /usr/lib64/root/libCore.so.6.38                                                                                                                                                                                                                                                                                                                                          
#13 0x00007fcec3fd9df5 in THashList::RecursiveRemove(TObject*) () from /usr/lib64/root/libCore.so.6.38                                                                                                                                                                                                                                                                                                                                      
#14 0x00007fcec3f7d33a in TROOT::RecursiveRemove(TObject*) () from /usr/lib64/root/libCore.so.6.38                                                                                                                                                                                                                                                                                                                                          
#15 0x00007fcec3488211 in TPave::~TPave() () from /usr/lib64/root/libGraf.so.6.38                                                                                                                                                                                                                                                                                                                                                           
#16 0x00007fcec348a895 in TPaveText::~TPaveText() () from /usr/lib64/root/libGraf.so.6.38                                                                                                                                                                                                                                                                                                                                                   
#17 0x00007fcec3fe4fe1 in TList::Clear(char const*) () from /usr/lib64/root/libCore.so.6.38                                                                                                                                                                                                                                                                                                                                                 
#18 0x00007fcec32f54cf in TPad::Close(char const*) () from /usr/lib64/root/libGpad.so.6.38                                                                                                                                                                                                                                                                                                                                                  
#19 0x00007fcec32f5899 in TPad::~TPad() () from /usr/lib64/root/libGpad.so.6.38                                                                                                                                                                                                                                                                                                                                                             
#20 0x00007fcec32f5a85 in TPad::~TPad() () from /usr/lib64/root/libGpad.so.6.38                                                                                                                                                                                                                                                                                                                                                             
#21 0x00007fcec3fe4fe1 in TList::Clear(char const*) () from /usr/lib64/root/libCore.so.6.38                                                                                                                                                                                                                                                                                                                                                 
#22 0x00007fcec32f54cf in TPad::Close(char const*) () from /usr/lib64/root/libGpad.so.6.38
#23 0x00007fcec32d82fc in TCanvas::Close(char const*) () from /usr/lib64/root/libGpad.so.6.38
#24 0x00007fcec32cf953 in TCanvas::Destructor() () from /usr/lib64/root/libGpad.so.6.38
#25 0x00007fcec32d2b6c in TCanvas::~TCanvas() () from /usr/lib64/root/libGpad.so.6.38
#26 0x00007fcec32d2bb5 in TCanvas::~TCanvas() () from /usr/lib64/root/libGpad.so.6.38
#27 0x00007fcec3fe8908 in TList::Delete(char const*) () from /usr/lib64/root/libCore.so.6.38
#28 0x00007fcec3fe4bdd in TList::Clear(char const*) () from /usr/lib64/root/libCore.so.6.38
#29 0x00007fcec3fda6da in TList::~TList() () from /usr/lib64/root/libCore.so.6.38
#30 0x00007fcec3fda875 in TList::~TList() () from /usr/lib64/root/libCore.so.6.38
#31 0x00007fcea15fa533 in ?? ()
#32 0x000000000000001f in ?? ()
#33 0x00007fff92418378 in ?? ()
#34 0x0000000000000004 in ?? ()
#35 0x00007f006e61654d in ?? ()
#36 0x000000000000001f in ?? ()
#37 0x0000000000000000 in ?? ()

I dont have simple macro to reproduce it yet, but i wanted to start discussion about it so we can interact and find the way how to correctly delete TList of TCanvas and other objects

Thanks

Martin


Please read tips for efficient and successful posting and posting code

Please fill also the fields below. Note that root -b -q will tell you this info, and starting from 6.28/06 upwards, you can call .forum bug from the ROOT prompt to pre-populate a topic.

ROOT Version: 6.38.00
Platform: Any
Compiler: g++ (GCC) 15.2.1 20251211


Dear @mvala ,

Thanks for reaching out! Do you need to manually delete the TList and other objects? Could we envision a way to ensure that only automatic memory management is applied via stack-based variables and std::unique_ptrs? There may be something missing even afterwards, but starting with that will give us a clear state to work from.

Cheers,
Vincenzo

Let’s start by this scenario. I am using TTree and i have one branch TList and i add different histogram, canvases, hstacks and so (i might add canvas and inside one histogram and addtionally i can added to the list), what is inside list i dont have control, because user is doing this. I fill TTree with many entries. When i am reading back by simple call many tree→GetEntry(...) i am getting memory leak. So, i tried to delete list before calling tree→GetEntry(...) . Here is part of source code
https://gitlab.com/ndmspc/ndmspc/-/blob/develop/core/NTreeBranch.cxx?ref_type=heads#L125

Since simple doing list→Delete() causing me double deletes, i let copilot to generate some function and he made one which i am using now

https://gitlab.com/ndmspc/ndmspc/-/blob/develop/base/NUtils.cxx?ref_type=heads#L1798

Dear @mvala ,

That looks like a lot of work just to workaround this double-delete issue, I hope we can improve the situation together!

I’m trying to understand how we could work towards a reproducer. Just to start with, you mention you have a TList branch and then you add histograms and other objects to this branch. Could this be some pseudo-code that would serve as a starting point for a reproducer?


auto f = std::make_unique<TFile>();
auto t = std::make_unique<TTree>();

TList l{};
t->Branch("mylist", &l);

for (n in n_entries){
    // Modify l, add objects to it
    t->Fill();
}

What would you add to this pseudo code to make it look like your example?
Cheers,
Vincenzo