In the following code, I create a TCanvas in the subroutine and then delete it, each time with its own different name (if I don’t do that, I cannot create the canvas in the main routine). However, after printing the main “canvas”, I have the sensation that the other 100 canvasses are still in memory somehow, although I deleted them. The screen is very slow, and I cannot zoom in the main-canvas. When I comment out the canvas lines in the subroutine, the main canvas works fine.
void TEST( int in_pixel );
int Main()
{
TH1D* h1 = new TH1D("h1", "MAIN", 100, 0., 100.0);
for (int pixel = 0; pixel < 100; pixel++)
{
TEST(pixel);
h1->Fill(50);
}
TCanvas* cv2 = new TCanvas("cv2", "", 1000, 500);
h1->Draw();
}
void TEST(int in_pixel)
{
TString cname("test_"); cname += in_pixel;
TCanvas* canvas = new TCanvas(cname, "", 500, 500);
delete canvas;
}
Sorry, I didn’t want to copy the entire code. In the subroutine, I plot a histogram with contents depending on “in_pixel” and each time plot it on a different Canvas, which I then print out to a file.
Of course, I could have one global Canvas, and re-use that same one again and again. But still, I’d like to understand why deleting a canvas does not work (seems like a memery leak to me).