I noted that if I use the Clear method (fast) I have a memory leak while Delete doesn’t (but program run much slower). Reading the forum I understood that the Clear method is safe “if the class in the array in turn does not contain pointers to objects”. Now a couple of questions…
In principle trigname.data() is just a character variable… Do you have any idea why it produce a leak with the Clear method?
Do you have any suggestion on how to change the above code in order to keep the same functionality (have a TClonesArray of string, TString, characters… it’s the same for me) but use the clear method and increase the performance of my code?
Hi
I’m not sure I understand what you mean… I’m filling the TClonesArray, not reading it… the suggestion you gave me seems to me meant to read the constructed array… And I have definitely a leak (memory increase steadily) while filling it.
the suggestion you gave me seems to me meant to read the constructed array.
The name of the function is missing leading you. It means ‘please return a constructed object at index # of the TClonesArray’. It is a replacement for the pattern “new ( clones[…] ) classname(…)”.
The main difference is that the new-with-placement will always construct (in the C++ meaning of the word) the object while ConstructedAt will construct the object with there was never an object in the slot or return the previous object if there have been one before.