| Summary: | Memory leak in G4ErrorPropagator when using PropagateOneStep method | ||
|---|---|---|---|
| Product: | Geant4 | Reporter: | Thomas Hauth <Thomas.Hauth> |
| Component: | error_propagation | Assignee: | Pedro.Arce |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | ||
| Priority: | P5 | ||
| Version: | 9.6 | ||
| Hardware: | All | ||
| OS: | All | ||
| Attachments: | Patch, Example code and valgrind output | ||
Thanks for reporting the problem and for the proposed fix. It will be included in the next patch release. |
Created attachment 214 [details] Patch, Example code and valgrind output Dear Geant4 experts, I discovered a possible memory leak and performance degradation bug in the Geant4 error propagation package. The source code in question is located in the file G4ErrorPropagator.cc. The class contained here provides two ways to propagate a track. Method 1: G4ErrorPropagator::Propagate | G4ErrorPropagator.cc:73 Method 2: G4ErrorPropagator::PropagateOneStep | G4ErrorPropagator.cc:188 The method PropagateOneStep, lacks the code to delete the G4Track object which was used in the previous track propagation. The Propagate method does this in line 119. According to the G4 user documentation and the example coming with the G4 source code, both method are intended to be called by the end user. Using PropagateOneStep for multiple tracks, will lead to an increasing memory footprint of the application and also degrade the runtime performance significantly. This behavior is fairly easy to reproduce with the errorpropagation example shipping with the Geant4 source code. However, this example itself contains a memory leak which will mask the actual memory loss in the Geant4 error propagation. Furthermore, I increased to number of propagations performed to 50000 in order to make the leak more detectable. Therefor, I appended also the modified example code together with the patch. Furthermore, you can find the vallgrind output reporting the leaked memory regions in the attachement. To reproduce, simply run the example with one of these environment variable set: G4ERROR_PROP=UNTIL_TARGET -> RSS mem consumption will be constant over time G4ERROR_PROP=STEP_BY_STEP -> RSS mem consumption will grow rapidly over time In my tests the STEP_BY_STEP is now 4 times faster than before and now as fast as the UNTIL_TARGET mode. Please find my proposal for a possible patch against the Geant 4.9.6.p01 release in the attachement. Thanks, Thomas