I am a bit confused about adding a TMultiGraph to another.
TMultiGraph::Add(TGraph*) inline documentation explicitly says that once you give TMultiGraph a TGraph, it owns it.
The code of TMultiGraph::Add(TMultiGraph*) seems similar enough to the TGraph* one… so, how should I use this feature? After a
pMGsmall->Add(pGraph); // add a TGraph
pMGbig->Add(pMCsmall); // add a TMultiGraph
who owns pGraph? will deleting pMGsmall and pMGbig try to delete pGraph twice?
Having it clarified in the documentation could also help.
Yes you are right, it looks like the graphs might be deleted twice. Have you encounter this problem ?
Do you have a small macro showing it ?
I was still in the design phase (of a 200-lines thing, nothing big), I was pondering my options and this one in particular. When I smelled trouble I freaked out and ran away (with a TObjArray).
So it’s more like thought-coding. My problem was that I could not even figure out how to do the thing correctly.
I have put together this:
TGraph* pGraph = new TGraph(10);
TMultiGraph* pMGsmall = new TMultiGraph("MGSmall", "The small one");
TMultiGraph* pMGbig = new TMultiGraph("MGBig", "The big one");
pMGsmall->Add(pGraph); // fill a multigraph with graphs
pMGbig->Add(pMGsmall); // fill a multigraph with other multigraphs
// ... err... now what? cleaning?
This explodes (segmentation fault) at the last line, regardless the order of the last two lines (ROOT 5.30/01).
But it might be because I did something stupid in the previous ones.
The backtrace points to TCollection::GarbageCollect(TObject*).
Yes, the TMultiGraph owns its content and thus you only need one delete: