[hist] Delete TMultiGraph::Add(TMultiGraph*, Option_t*) overload
#20869
+9
−27
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
TMultiGraph::Add(TMultiGraph*, Option_t*)overload that adds the graphs in another TMultiGraph to a TMultiGraph is removed without deprecation. It was inconsistent from a memory ownership standpoint. A TMultiGraph always owns all the added graphs, so adding the same graph instances to two TMultiGraphs forcibly led to double-deletes. The ownership behavior could also not be changed, which gets clear from the TMultiGraph destructor, which always callsTList::Delete()on the collection that holds the TGraphs.No deprecation period is defined, because as the overload unavoidibly leads to double-deletes, it is likely not used. Or at least rarely used, because it can work if one of the two TMultiGraphs is leaked on purpose.
If you want to add all graphs from
otherMultiGraphtomultiGraph, one should use a for-loop and clone the graphs instead:Some examle code with the double-delete:
{ auto mg1 = new TMultiGraph(); auto mg2 = new TMultiGraph(); auto gr1 = new TGraph(); mg1->Add(gr1); auto gr2 = new TGraph(); mg1->Add(gr2); mg2->Add(mg1); // This is the Add(TMultiGraph* overload) delete mg1; delete mg2; }This is a spinoff from #13593, triggered by a question from @vepadulano (#13593 (comment)).