[ROOT] Memory Leak?

From: Dr. D. Sideris (d.sideris@ic.ac.uk)
Date: Fri Nov 24 2000 - 12:10:10 MET


Dear Rooters. I create an application (VC++) and then open
a canvas and the plot a pad inside the canvas. The function runs fine. But
after I call the function approx 20 times (via a button press) the program
crashes with 'memory could not be accessed...' error. I would appreciate it
if you can see what I'm doing wrong in the code below. Is there a way to make shure or check whether root cleans up it's self properly? Thanks

Dimitris


// global.h: interface for the myclass class.
//
//////////////////////////////////////////////////////////////////////


class TApplication;

class Global {
public:

  Global();
  ~Global();
  int Report(void);

private:

TApplication *canv;

};


//////Global.cpp

#include <fstream.h>
#include <stdlib.h>
#include <iostream.h>
#include "Global.h"

#include "TRoot.h"
#include "TApplication.h"
#include "TCanvas.h"
#include "TH1.h"
#include "TH2.h"
#include "TFile.h"
#include "TBrowser.h"
#include "TTree.h"
#include "TF1.h"
//#include "afx.h"
#include "TKey.h" //Must be after afx include since they both have a GetClassName member!
#include "A.h"
#include "A_cint.h"



Global::Global() {
   canv = new TApplication("App", 0, 0);

}

 Global::~Global() {
  Int_t status=0;
  canv->Terminate(status);
 }

Int_t Global::Report()
{

    TCanvas *c = new TCanvas("c", "The Hello Canvas", 800, 600);
    TPad *pad1 = new TPad("pad1","The pad with the function",0.03,0.062,0.98,0.92,21);
    pad1->Draw();
    pad1->cd();

  c->Update();
  canv->Run(kTRUE);


 if (pad1) {
  pad1->Clear();
  pad1->Close();
  delete pad1;
 }

 if (c) {
  c->Clear();
  c->Close();
  delete c;
 }
 return 0;
}



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:37 MET