Stringstream Leaks Memory

Hello,

I believe this is the standard way in C++ to clear memory of a stringstream, but when I run it in ROOT, it eats up a lot of memory. Is there an easy solution to this problem?

Thanks,
Lenny

RooRealVar *signal = new RooRealVar("signal", "signal", -2, 20);

RooRealVar *mean = new RooRealVar("mean",
                       "mean",
                       0,20);

RooRealVar *sigma = new RooRealVar("sigma",
                        "sigma",
                        0,20);

stringstream var_cache;

for(Int_t l=0;l<100000000;l++){
    cout<<l<<endl;
    sigma.setVal(l/50);
    RooGaussian *test_fit_model = new RooGaussian("test_fit_model","test_fit_model",*signal,*mean,*sigma);
    test_fit_model->getVariables()->writeToStream(var_cache, kFALSE);
    delete test_fit_model;
    var_cache.str(string());
    var_cache.clear();
    }

Hi Lenny,

There is no issue with your use of stringstream.
However the function: test_fit_model->getVariables() returns an object that must be deleted explicitly.
To solve the memory leak use: RooArgSet* tmp = test_fit_model->getVariables(); tmp->writeToStream(var_cache, kFALSE); delete tmp;

Cheers,
Philippe.