Memory issues creating/deleting RooFit objects in loop

I’m trying to debug some memory issues I’m having with my c++ code with RooFit. To do that, I’ve simplified it to just creating and deleting objects within the same loop (in my actual code I am pushing the RooDataSet to a vector and then deleting it later on). When I run this simplified code, my program grows significantly in memory as the iteration number increases.

for (Int_t i=0; i < names.size(); i++) {
    RooDataSet* dataSet = new RooDataSet(names.at(i)+"DataSet",names.at(i)+"DataSet",*observable);
    dataSet->Delete();
}

I’m doing something wrong, but I’m not sure what. Any advice? Thanks!

I ended up moving the creation of a vector of RooDataSets to outside the loop they were in, and then using a reset() command on those vector elements prior to filling them. This got rid of the problem. Interestingly I do something similar with a few other RooFitObjects (RooHistPdf, RooAddPdf, and RooSimultaneous) inside a loop and those don’t seem to lead to memory increasing rapidly, so maybe this is specific to RooDataSet objects? Or maybe those objects are just smaller so the memory increase isn’t as noticeable.

It’s likely that you are not fully deleting the dataset. Try using
delete dataSet;, the proper c++ way of deleting something. Maybe even wrap that thing in a smart pointer or directly put it on the stack if you are using it only once in a loop.

I would advise not to use the Delete() function. It only has an effect if you run this from the interpreter (and maybe not even that, any more).

Hi StephanH,
I tried using delete instead and it actually caused the memory usage to grow even quicker than the Delete() function. I have not tried smart-pointers so I can look into that. Thank you for your insight on the use of Delete(), I’m using Delete() elsewhere in my code and will switch that over to C++ deletes. Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.