This short python script:
#! /usr/bin/env python
c1 = ROOT.TCanvas('c', 'c')
c2 = ROOT.TCanvas('c', 'c')
generates a warning:
TCanvas:0: RuntimeWarning: Deleting canvas with same name:
I tried to call
which generates a warning:
TCanvas::Delete():0: RuntimeWarning: may not use this method
How to solve this problem, given that the canvas name ‘c’ is fixed?
Interestingly, there is no problem with canvas names in the c++ equivalent:
TCanvas c1("c", "c");
TCanvas c2("c", "c");
Where is there a difference between python and c++?
I believe the difference is due to this line:
The C++ object that PyROOT wraps is allocated on the heap, while from C++ you are allocating that object on the stack. If you create your object with
new in C++ you will see the same warning.
The will be no leak, it is just ROOT warning you that it will destroy the other canvas.
Indeed. I would not have imagined that allocating on stack or on heap would cause any functional difference.
Then how to solve? TCanvas::Close()?
@couet any advice on this?
@Viesturs you are worried about the warning? It should not interfere with what you want to do in the end.
Creating two different canvases with the same name is not a good idea anyway as ROOT tracks the objects in memory . You are just making things confusing. Use different names and it should be fine.
@couet, in the real situation canvases are created in a loop. Should I call TCanvas::Close() on the canvas from the previous iteration?
Even if you create the canvases in a loop you can specify different names.
Imagine “i” is the index of the loop. In C++ you can do:
TCanvas c1(Form("c%d",i), Form("c%d",i));
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.