I'm experiencing a memory leak in my application that uses Geant4 that is noticeable and problematic for large (~250k) numbers of events. I'm running protons in targets with no secondaries to look at diffractive scattering. Profiling using Xcode Instrument's leak tool, I find a leak in G4FPFModel in GetStrings(). Indeed reading the code, you can see one. Line 290 - theStrings = new G4ExcitedStringVector Line 327 - theStrings = BuildStrings() BuildStrings always allocates a new G4ExcitedStringVector. The pointer is returned from this function and overwrites the previous pointer. Therefore, we now have no pointer to the original object and it's leaked. A simple fix is to put delete theStrings just before BuildStrings, however, I presume the initial allocation is so that we always return a valid object from this function. There are a few ways to remedy this that are clearer. You could pass the pointer to BuildStrings() becomes BuildStrings(theStrings). The leak is relatively small, but it builds up. In our simulations we see around 0.8Mb/s with secondaries killed. I think this is also in Geant4.10.4.p02. Hopefully I've identified it correctly and this helps. Best, Laurie
This was introduced in 10.5, in releases before theStrings was initialised to 0. Its a local variable not passed to any method, just being re-assigned by BuildsStrings(). Need to check with the author why the initial new ... was added.
The leak has been fixed in the coming patch G4 10.5.p01 (expected to be released this week), and in the development (i.e. for the future G4 10.6 release). Thanks for the report.