Dear Rene
Thank you, does this mean that in the following code
fragment, graph will be deleted by TPad?
TGraph *graph = 0;
for (Int_t i=0; i<m; i++) {
graph = new TGraph(n, x, y);
graph->SetBit(kCanDelete);
graph->Draw(opt);
}
Best regards
Christian
Rene Brun wrote:
> Hi Christian,
>
> I suggest to read the chapter on "Object Ownership", page 107
> of the ROOT Users Guide.
>
> When you do
> graph->DrawGraph(n, x, y, opt);
> DrawGraph creates a copy of the graph and sets its bit kCanDelete.
> When clearing the pad, objects with the kCanDelete bit set are
> automatically deleted. In your case, I suggest to do:
> TGraph graph; //will be automatically delete when leaving scope
> for (Int_t i=0; i<m; i++) {
> graph.DrawGraph(n, x, y, opt); //newgraph=new TGraph()
> }
>
> Rene Brun
>
>
> On Sat, 30 Nov 2002, cstrato wrote:
>
>
>>Dear Rooters
>>
>>In the following code, no graph is drawn if I delete graph:
>> TGraph *graph = 0;
>> for (Int_t i=0; i<m; i++) {
>> graph = new TGraph(n, x, y);
>> graph->Draw(opt);
>> SafeDelete(graph); //<== not possible
>> }
>>
>>However, in this code I can delete graph because DrawGraph
>>creates a new graph "newgraph":
>> TGraph *graph = 0;
>> for (Int_t i=0; i<m; i++) {
>> graph = new TGraph(n, index, x);
>> graph->DrawGraph(n, x, y, opt); //newgraph=new TGraph()
>> SafeDelete(graph);
>> }
>>
>>I understand that root takes care of deleting TGraph objects,
>>but is this also the case when I create a standalone program
>>or does there exist a memory leak?
>>
>>
>>Thank you in advance for your help.
>>
>>Best regards
>>Christian
>>_._._._._._._._._._._._._._._._
>>C.h.i.s.t.i.a.n S.t.r.a.t.o.w.a
>>V.i.e.n.n.a A.u.s.t.r.i.a
>>_._._._._._._._._._._._._._._._
>>
>>
>>
>
>
>
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:22 MET