Problem 1466 - Memory leak in G4ErrorPropagator when using PropagateOneStep method
Summary: Memory leak in G4ErrorPropagator when using PropagateOneStep method
Status: RESOLVED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: error_propagation (show other problems)
Version: 9.6
Hardware: All All
: P5 normal
Assignee: Pedro.Arce
URL:
Depends on:
Blocks:
 
Reported: 2013-05-09 14:21 CEST by Thomas Hauth
Modified: 2013-05-16 09:53 CEST (History)
0 users

See Also:


Attachments
Patch, Example code and valgrind output (20.00 KB, application/gzip)
2013-05-09 14:21 CEST, Thomas Hauth
Details

Note You need to log in before you can comment on or make changes to this problem.
Description Thomas Hauth 2013-05-09 14:21:39 CEST
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
Comment 1 Gabriele Cosmo 2013-05-16 09:53:40 CEST
Thanks for reporting the problem and for the proposed fix.
It will be included in the next patch release.