I have a class in which I use a TH1F object all the time again and again, and the result is that somehow the memory of my pc just gets more less as it runs. I Fill the TH1F in a loop a lot of time and I need to empty it and reuse again. I don’t understand why it eats more and more memory when I declare my TH1F histo in the header of my class and I construct it in the constructor of my class and delelte it in the destructor. The only thing that happens is that I ‘empty’ the histo in this way:
histo->Add(histo, -1);
which is - I think - a bad solution for using the same histo a million times. So can you give a better solution for using the same histo a miilion times and without eating all my 512 Mbyte memory?
Hi,
where’s the loop? I now have to guess what you’re doing, to be able to reproduce your mem leak. My guess is attached, and it does not produce a mem leak. I’m running it as “.x test.C”.
Both of us could have saved some time if you had sent me a running macro that shows your mem leak…
Axel.
Sorry for being late but there was no reply to my original question for more than 1 day, that is why I thought maybe it is a trivial problem and needs no answer.
Here is the code attached. I use my own classes in the script that needs to be loaded into Cint.
You may start the scripts with : .x testfitroot.C(5, 5, 4000, 4500, 4000, 4500, 1600, 2150);
This script is about to connect ot a mysql server and get data from there, then fill a histo with them. After this I need to empty the histo, and reuse it again for the next data-set from the mysql server. You can see the server name, and a public user name with password in the script that allows one only to “select” from the database. If it doesn’t run it may be because of network problems.
I am not sure that the TH1F eats my memory, but I can’t figure out what memory allocation is the wrong one. Maybe I don’t delete something, I am not sure…
Hi,
you need to delete the TSQLResults after using them. The server’s Query creates a new one each time you call it, and it’s the user’s responsibility to delete it.
Axel.