How to delete object drawn with DrawClone()?

Dear ROOT expert,
I’m drawing a lot of TGraph in several loops, since the TGraph are very similar I’m drawing them with DrawClone(), then I recreate then, then I draw them again and so on. I’d like to delete these objets both for cleaning up memory and for cleaning the canvas. Is it possibile?

General idea

// create graphWithAxis
auto c1 = TCanvas();

for(int iEvt=0; iEvt<nEvents;iEvt++){
  //set branches to iEvt

  for(int iMB=1; iMB<=4; iMB++){
    vector<float> x[5], y[5];
    // fill x and y, depending on iMB
    TGraph **gr = new TGraph*[5];
    for(int i=0;i<5;i++){
        gr[i] = new TGraph(x[i].size(),&x[i][0],&y[i][0]);
      }else{ gr[i]=nullptr; }
    for(int i=0;i<5;i++) delete gr[i];
    delete[] gr;
  // DELETE CLONES <-------

delete c1;

Many Thanks,

Try something like this:

TGraph *clones[5];
clones[i] = gr[i]->DrawClone("PSAME");
for (int i=0;i<5;i++) {
   delete gr[i];
   delete clones[i];

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