Delete canvas after canvas->connect

Hello,

I have a small problem deleting TCanvas* canvas after using canvas->Connect()

		canvas->Connect("Closed()", "TApplication", tApp,  "Terminate()");	
		tApp->Run(kTRUE);
//		gSystem->Exit(0,kFALSE);
		delete canvas;
		delete tApp;

So when I click on “Quit Root”, “delete canvas” works, if I close canvas I get “segmentation violation” when deleting canvas. I was trying canvas->Disconnect() but didnt work either.

Thanks for any help.

this little program reproduces my problem

#include <iostream>

#include "TROOT.h"
#include "TApplication.h"
#include "TCanvas.h"

int main(int argc, char** argv)
{
	TApplication* tApp=new TApplication("test",&argc,argv);
	TCanvas* canvas=new TCanvas("canvas","canvas",10,10,300,300);
	canvas->Draw("AP");
	canvas->Connect("Closed()", "TApplication", tApp,  "Terminate()");
	tApp->Run(kTRUE);
	delete canvas;
	delete tApp;		
	return 0;
}

Using no pointers does not work either.
ROOT v5.34/00 Lubuntu 13.04

Hi,

The problem comes from the fact that the canvas is deleted in the TRootCanvas destructor when closing it. So I would suggest to simply no deleting it yourself…

Cheers, Bertrand.

following your argument this should work, right?

#include <iostream>

#include "TROOT.h"
#include "TApplication.h"
#include "TCanvas.h"

int main(int argc, char** argv)
{
	TApplication tApp("test",&argc,argv);
	TCanvas canvas("canvas","canvas",10,10,300,300);
	canvas.Connect("Closed()", "TApplication", &tApp,  "Terminate()");
	canvas.Draw("AP");
	
	tApp.Run(kTRUE);
	
	return 0;
}

but it does not :frowning: .

[quote=“misukin”]following your argument this should work, right?[/quote]Nope, because when going out of scope, the canvas is deleted as well…

Cheers, Bertrand.