In the TGraph2D::Clear I find: if (fFunctions) { delete fHistogram; fHistogram = 0; } Don’t you think there should be “if (fHistogram) {” (otherwise, in some cases, I see no way to “free” the memory allocated by the “fHistogram”)?

Why doesn’t this method set “fSize = 0” and “fNpoints = 0;”?

It seems to me that after I call “My2DGraph->Clear();”, I can no longer really re-use “My2DGraph”.

Your points are very valid. I will do the changes and test.

I have done these mods in the trunk and in 5.34.

Well, I still think that I am not able to reuse “My2DGraph” …
Several problems in the “Clear” method that I still see (just at “first look”):

  1. the “fFunctions” gets deleted and there’s no way to recreate it afterwards,
  2. the “fUserHisto” is not maintained (one deletes the “fHistogram”, though),
  3. some another data members of the TGraph2D are not maintained.
    Maybe you should make the “Clear” method “protected” (like the “Build” method), so that “ordinary” users will not be allowed to use it?
    Well, the “TGraph2D” is the only “graph” class that has this method (though it derives from “TNamed” and so there might be a problem in “hiding” its virtual “Clear”).
    It seems to me that the only places which use “Clear” are the “destructor” and the “operator=”.

And I’m not sure about the “TGraph2DErrors” … it derives from “TGraph2D” … but the “fEX”, “fEY” and “fEZ” will not be deleted by “Clear”.

Since my mods, the tests I did showed me that I can reused a TGraph2D after having cleared it.
Before the mods I could not.
Can you provide a small script showing the problem ?