How to close or delete a canvas inside a macro?

Hi Everyone,

In the ROOT shell when I do


where “canv” is my TCanvas. It works perfectly, but it doesn’t seem to close my canvas within a program ! How can I properly close or delete a canvas after using it ? Within my code I will need to open and close several canvases.


if (canv) { canv->Close(); gSystem->ProcessEvents(); }

Thanks for your reply. I would also like to know, how can I check if the canvas did close ? Something like another if(canv)std::cout<<"Didn't close\n"; is it possible ?

Yes, but then you have do do this:

if (canv) { canv->Close(); gSystem->ProcessEvents(); delete canv; canv = 0; }

Thanks very much Bertrand, it works like a charm.