A question about object ownership

I use win32gdk version 3.10/2
I have a class A which has a TGraph as a member. In A, a TF1 object is created and then attached it to the TGraph member using TGraph::GetListOfFunctions()->Add(). I have two instances of A:
pA is a pointer to the original
pSave = (A*)pA->Clone() is a pointer to a copy.

If I delete pA, pSave is still intact - as it should be. However, when I create a new instance of A, in particular, when the new TF1 is created, the TF1 attached to the TGraph member of pSave gets deleted! This makes no sense to me at all. I’ve attached simple a VC++6.0 project that demonstrates the problem.

Any help here greatly appreciated. Thanks!

example.zip (3.47 KB)

Hi Ed,

When you graph->Add(myTF1);
do also


Hi Rene,
That almost works! It is still necessary to go into A::Streamer() since A::Clone() evidently adds the TF1 into the ROOT list of functions.

I’m puzzled about the purpose of ROOT’s ListOfFunctions. Why does the TF1 ctor delete TF1’s if they have the same name rather than remove them from the list?

Thanks for the help!