Re: [ROOT] Memory Leak?

From: Valeri Fine (Faine) (fine@bnl.gov)
Date: Fri Nov 24 2000 - 21:47:54 MET


Dear Dimitris

----- Original Message ----- 
From: Dr. D. Sideris <d.sideris@ic.ac.uk>
To: <roottalk@cern.ch>
Subject: [ROOT] Memory Leak?


> 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

 From your example it is not very clear what did you mean speaking "root"
 It sounds you did not use "root.exe" provided rather your own application.
 Then it is your application responsibility:

 "to make shure or check whether root cleans up it's self properly"

Making your own interactive "root-like" application requires one understands the
original ROOT deeply. The recommended way is to create a custom DLL and 
load it with the ROOT.EXE provided. If this doesn't work and you know why 
then you can go to your custom "ROOT-like" application

What about your concrete question I would like to understand what was your goal and 
see how one can reproduce your problem with his / her computer.

 I did not get which button one "has to press" to call your "function" (which "function" ?)
20 times ?

  My suspicion is you instantiated TApplication many times This may cause
  some problem.  What was a reason for that ?

  With my regards,
              Valery

===========================================

// 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"
file://#include "afx.h"
#include "TKey.h" file://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