TMultigraph and memory leak question

Hello,

I have a

and I add each of the TGraphErrors to a TMultiGraph like

Now the documentation states that “Deleting the TMultiGraph object will automatically delete the graphs.
You should not delete the graphs when the TMultigraph is still active.”

Do I understand correctly that I do not need to do

for (std::vector<TGraphErrors*>::const_iterator it = tmperrorgraph.begin(); it != tmperrorgraph.end(); ++it) { delete *it; } tmperrorgraph.clear();

i.e. ROOT will do it for me, when fMultigraph is deleted?

Thank You,

Bertrand Roessli

The best is to try. Uncomment “delete g” in the following macro and you will get a Seg Fault on g1->Draw()

{
   TCanvas *c1 = new TCanvas("c1","c1",600,400);

   Double_t x1[2]  = {2.,4.};
   Double_t dx1[2] = {0.1,0.1};
   Double_t y1[2]  = {2.1,4.0};
   Double_t dy1[2] = {0.3,0.2};

   Double_t x2[2]  = {3.,5.};
   Double_t dx2[2] = {0.1,0.1};
   Double_t y2[2]  = {3.2,4.8};
   Double_t dy2[2] = {0.3,0.2};

   gStyle->SetOptFit(0001);

   TGraphErrors *g1 = new TGraphErrors(2,x1,y1,dx1,dy1);
   g1->SetMarkerStyle(21);
   g1->SetMarkerColor(2);

   TGraphErrors *g2 = new TGraphErrors(2,x2,y2,dx2,dy2);
   g2->SetMarkerStyle(22);
   g2->SetMarkerColor(3);

   TMultiGraph *g = new TMultiGraph();
   g->Add(g1);
   g->Add(g2);

//   delete g;

   g1->Draw("ap");
}