A lament on ROOT's memory management

I have recently spent a comical half-hour debugging a standalone C++ program that I have written that uses Minuit2 to do some fitting. After much ado I found that the TFitterMinuit, when deleted, feels that it is its duty to also delete the pointer to my FCNBase-derived object, which I was also trying to delete. Although I am permitted to delete one or the other, I am not permitted to delete both. Now I’ve been using ROOT for five years or so now, and at first I was mystified when I didn’t have to delete all the histograms I myself allocated in my first standalone programs, but I grew to accept that a force beyond my reckoning was making sure I had no memory leaks. And I must admit that within the interpreter such sloppy pointer management is mandatory if you want to actually look at any histograms you’ve drawn after your macro exits. But now we are talking about a class that I wrote, dammit! I was the one who spent all the time trying to figure out what in God’s holy name Moneta was thinking when he wrote this package since he didn’t see fit to comment hardly anything, and I spent the time re-learning the interface to use a package that I later find out is over a factor of two slower than the previous version, which I didn’t even know was still in use because there are two pages in the manual telling me nothing about how to actually use it in code. I think that by that measure I have earned the right to manage my own memory at least in this case. Stop making it easier for me to write crappy code! I actually get excited when I get to delete something that I allocated–to anyone else programming in C++ outside of the ROOT world that is complete insanity. I should be cursing over having to delete every little thing.

OK now I feel better. Thanks for listening if you made it this far.

Hello,

the TFitterMinuit class has been designed to integrate Minuit2 with the old ROOT fitting classes. Normally a user pass the FCN as a free function, so the object being deleted it is just a simple wrapper.
There is a possibility to pass an object for the FCN via TFitterMInuit::SetMinuitFCN. You shoud read the documentation, see
root.cern.ch/root/htmldoc/TFitte … tMinuitFCN
where it is said clearly that the ownership is passed.
I agree this is not optimal and it could be improved. However, this class is now being deprecated and it is not the recommended way of using Minuit2.
If you read again the documentation, see
project-mathlibs.web.cern.ch/pro … index.html

from 5.17.08, the recommended way to use Minuit2 is via the class ROOT::Minuit2::Minuit2Minimizer. See the reference doc:
project-mathlibs.web.cern.ch/pro … mizer.html
This class provides an OO interface to the package and I hope it helps in writing better C++ code. I would be grateful if you have any feedback to give.

I apologize that the documentation is not complete, in particular in the ROOT User Guide and for Minuit2 itself. I am not the original author of Minuit2, but I agree that its internal documentation is rather poor. However, there is a Minuit2 User guide, (seal.web.cern.ch/seal/documents/ … sguide.pdf), but it needs probably to be updated.
I hope you are able now to find the documentation and eventually read it. If you have any question please let me know
Best Regards

Lorenzo

Thanks for replying Lorenzo, despite my rudeness. I think my frustration is more with ROOT as a whole and this is just an example of such. With respect to feedback for Minuit2 and its ROOT interface, I claim that the first place any documentation for any new package, especially one that makes another obsolete, should be in the User’s Guide. I think that is where most average ROOT users first look when they want to try out a feature they are unfamiliar with. Expecting users to check the release notes to make sure the User’s Guide isn’t outdated is silly. For me, when there was very little in the User’s Guide to tell me how to actually use TMinuit in a program, I went searching on Google. There I found very little in terms of examples for TMinuit, but I did find a good one for TFitterMinuit, which I what I ended up using. Incidentally, the link you gave for Minuit2Minimizer:

project-mathlibs.web.cern.ch/pro … index.html

contains an example `testMinimize.cxx’ which actually implements the TFitterMinuit interface. I didn’t see anything on there implementing the Minuit2Minimizer interface.

Bottom line, when you’ve got three different ROOT interfaces to two minimization packages, all with questionable documentation, you’re going to get people frustrated.

Thanks for explaining what you could. Seeing as how all of this seems very much in flux, I think it’s probably best to try using Minuit outside of ROOT.

Hello,

you are right the link from the page I gave you points to the wrong example. The right example is actually this one

root.cern.ch/viewvc/trunk/math/m … iew=markup

There is also new and updated documentation for minimization in our new Web site, see

root.cern.ch/drupal/content/nume … nimization

I agree we should put all this in the User Guide. We are thinking of moving to an online version of the User Guide in order to have it updated more frequently.

Lorenzo