Problem 2026 - memory leak in G4ParticleHPContEnergyAngular::Sample() and G4ParticleHPContAngularPar::cacheInit()
Summary: memory leak in G4ParticleHPContEnergyAngular::Sample() and G4ParticleHPContAn...
Status: RESOLVED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: processes/hadronic/models/neutron_hp (show other problems)
Version: 10.4
Hardware: All All
: P4 trivial
Assignee: dennis.herbert.wright
URL:
: 2077 (view as problem list)
Depends on:
Blocks:
 
Reported: 2017-12-18 20:29 CET by Artem Zontikov
Modified: 2018-11-15 15:47 CET (History)
2 users (show)

See Also:


Attachments
memory leak (3.88 KB, application/gzip)
2017-12-18 20:29 CET, Artem Zontikov
Details

Note You need to log in before you can comment on or make changes to this problem.
Description Artem Zontikov 2017-12-18 20:29:18 CET
Created attachment 483 [details]
memory leak

Hi.

There is a huge memory leak here: 

==30905== 10,105,920 bytes in 210,540 blocks are definitely lost in loss record 12,844 of 12,844
==30905==    at 0x4C28203: operator new(unsigned long) (vg_replace_malloc.c:334)
==30905==    by 0xE6364D1: cacheInit (G4ParticleHPContAngularPar.hh:199)
==30905==    by 0xE6364D1: G4ParticleHPContAngularPar::G4ParticleHPContAngularPar(G4ParticleDefinition*) (G4ParticleHPContAngularPar.cc:63)
==30905==    by 0xE63F291: G4ParticleHPContEnergyAngular::Sample(double, double, double) (G4ParticleHPContEnergyAngular.cc:84)
==30905==    by 0xE616807: G4ParticleHPProduct::Sample(double, int) (G4ParticleHPProduct.cc:124)
==30905==    by 0xE6537A9: G4ParticleHPEnAngCorrelation::Sample(double) (G4ParticleHPEnAngCorrelation.cc:195)
==30905==    by 0xE62D0A4: G4ParticleHPCaptureFS::ApplyYourself(G4HadProjectile const&) (G4ParticleHPCaptureFS.cc:90)
==30905==    by 0xE630D02: G4ParticleHPChannel::ApplyYourself(G4HadProjectile const&, int) (G4ParticleHPChannel.cc:308)
==30905==    by 0xE6265DC: G4ParticleHPCapture::ApplyYourself(G4HadProjectile const&, G4Nucleus&) (G4ParticleHPCapture.cc:141)
==30905==    by 0xE22B990: G4HadronicProcess::PostStepDoIt(G4Track const&, G4Step const&) (G4HadronicProcess.cc:350)
==30905==    by 0xD60DBB8: G4SteppingManager::InvokePSDIP(unsigned long) (G4SteppingManager2.cc:538)
==30905==    by 0xD60E05E: G4SteppingManager::InvokePostStepDoItProcs() (G4SteppingManager2.cc:510)
==30905==    by 0xD60B224: G4SteppingManager::Stepping() (G4SteppingManager.cc:209)

because cached structure is not deleted in class destructor.

And here:

==30905== 8,529,696 bytes in 4 blocks are possibly lost in loss record 12,843 of 12,844
==30905==    at 0x4C28203: operator new(unsigned long) (vg_replace_malloc.c:334)
==30905==    by 0xE63E27B: allocate (new_allocator.h:104)
==30905==    by 0xE63E27B: _M_allocate (stl_vector.h:168)
==30905==    by 0xE63E27B: std::vector<G4ParticleHPContAngularPar::toBeCached*, std::allocator<G4ParticleHPContAngularPar::toBeCached*> >::_M_fill_insert(__gnu_cxx::__normal_iterator<G4ParticleHPContAngularPar::toBeCached**, std::vector<G4ParticleHPContAngularPar::toBeCached*, std::allocator<G4ParticleHPContAngularPar::toBeCached*> > >, unsigned long, G4ParticleHPContAngularPar::toBeCached* const&) (vector.tcc:483)
==30905==    by 0xE63661A: insert (stl_vector.h:1024)
==30905==    by 0xE63661A: resize (stl_vector.h:687)
==30905==    by 0xE63661A: Initialize (G4CacheDetails.hh:201)
==30905==    by 0xE63661A: GetCache (G4Cache.hh:121)
==30905==    by 0xE63661A: Get (G4Cache.hh:283)
==30905==    by 0xE63661A: G4ParticleHPContAngularPar::G4ParticleHPContAngularPar(G4ParticleDefinition*) (G4ParticleHPContAngularPar.cc:63)
==30905==    by 0xE63F291: G4ParticleHPContEnergyAngular::Sample(double, double, double) (G4ParticleHPContEnergyAngular.cc:84)
==30905==    by 0xE616807: G4ParticleHPProduct::Sample(double, int) (G4ParticleHPProduct.cc:124)
==30905==    by 0xE6537A9: G4ParticleHPEnAngCorrelation::Sample(double) (G4ParticleHPEnAngCorrelation.cc:195)
==30905==    by 0xE62D0A4: G4ParticleHPCaptureFS::ApplyYourself(G4HadProjectile const&) (G4ParticleHPCaptureFS.cc:90)
==30905==    by 0xE630D02: G4ParticleHPChannel::ApplyYourself(G4HadProjectile const&, int) (G4ParticleHPChannel.cc:308)
==30905==    by 0xE6265DC: G4ParticleHPCapture::ApplyYourself(G4HadProjectile const&, G4Nucleus&) (G4ParticleHPCapture.cc:141)
==30905==    by 0xE22B990: G4HadronicProcess::PostStepDoIt(G4Track const&, G4Step const&) (G4HadronicProcess.cc:350)
==30905==    by 0xD60DBB8: G4SteppingManager::InvokePSDIP(unsigned long) (G4SteppingManager2.cc:538)
==30905==    by 0xD60E05E: G4SteppingManager::InvokePostStepDoItProcs() (G4SteppingManager2.cc:510)

due to resizing of std::vector at every function call.

Both leaks take place with incident neutrons when php_as_hp is not set.

Deleting cached structure in G4ParticleHPContAngularPar dtor is only a partial solution as the problem with G4Cache remains: 

==3495== 2,154,912 (96 direct, 2,154,816 indirect) bytes in 4 blocks are definitely lost in loss record 12,829 of 12,836
==3495==    at 0x4C28203: operator new(unsigned long) (vg_replace_malloc.c:334)
==3495==    by 0xE63E5F9: Initialize (G4CacheDetails.hh:199)
==3495==    by 0xE63E5F9: GetCache (G4Cache.hh:121)
==3495==    by 0xE63E5F9: Get (G4Cache.hh:283)
==3495==    by 0xE63E5F9: ClearHistories (G4ParticleHPContAngularPar.hh:192)
==3495==    by 0xE63E5F9: G4ParticleHPContEnergyAngular::ClearHistories() (G4ParticleHPContEnergyAngular.cc:128)
==3495==    by 0xE61678F: G4ParticleHPProduct::Sample(double, int) (G4ParticleHPProduct.cc:116)
==3495==    by 0xE653CA9: G4ParticleHPEnAngCorrelation::Sample(double) (G4ParticleHPEnAngCorrelation.cc:195)
==3495==    by 0xE62CF5C: G4ParticleHPCaptureFS::ApplyYourself(G4HadProjectile const&) (G4ParticleHPCaptureFS.cc:90)
==3495==    by 0xE6308D2: G4ParticleHPChannel::ApplyYourself(G4HadProjectile const&, int) (G4ParticleHPChannel.cc:308)
==3495==    by 0xE6265BC: G4ParticleHPCapture::ApplyYourself(G4HadProjectile const&, G4Nucleus&) (G4ParticleHPCapture.cc:141)
==3495==    by 0xE22B970: G4HadronicProcess::PostStepDoIt(G4Track const&, G4Step const&) (G4HadronicProcess.cc:350)
==3495==    by 0xD60DBB8: G4SteppingManager::InvokePSDIP(unsigned long) (G4SteppingManager2.cc:538)
==3495==    by 0xD60E05E: G4SteppingManager::InvokePostStepDoItProcs() (G4SteppingManager2.cc:510)
==3495==    by 0xD60B224: G4SteppingManager::Stepping() (G4SteppingManager.cc:209)
==3495==    by 0xD615FF4: G4TrackingManager::ProcessOneTrack(G4Track*) (G4TrackingManager.cc:126)
==3495== 
==3495== 6,405,280 bytes in 3 blocks are possibly lost in loss record 12,836 of 12,836
==3495==    at 0x4C28203: operator new(unsigned long) (vg_replace_malloc.c:334)
==3495==    by 0xE63DE4B: allocate (new_allocator.h:104)
==3495==    by 0xE63DE4B: _M_allocate (stl_vector.h:168)
==3495==    by 0xE63DE4B: std::vector<G4ParticleHPContAngularPar::toBeCached*, std::allocator<G4ParticleHPContAngularPar::toBeCached*> >::_M_fill_insert(__gnu_cxx::__normal_iterator<G4ParticleHPContAngularPar::toBeCached**, std::vector<G4ParticleHPContAngularPar::toBeCached*, std::allocator<G4ParticleHPContAngularPar::toBeCached*> > >, unsigned long, G4ParticleHPContAngularPar::toBeCached* const&) (vector.tcc:483)
==3495==    by 0xE6361EA: insert (stl_vector.h:1024)
==3495==    by 0xE6361EA: resize (stl_vector.h:687)
==3495==    by 0xE6361EA: Initialize (G4CacheDetails.hh:201)
==3495==    by 0xE6361EA: GetCache (G4Cache.hh:121)
==3495==    by 0xE6361EA: Get (G4Cache.hh:283)
==3495==    by 0xE6361EA: G4ParticleHPContAngularPar::G4ParticleHPContAngularPar(G4ParticleDefinition*) (G4ParticleHPContAngularPar.cc:63)
==3495==    by 0xE63EE47: G4ParticleHPContEnergyAngular::Sample(double, double, double) (G4ParticleHPContEnergyAngular.cc:84)
==3495==    by 0xE6167E7: G4ParticleHPProduct::Sample(double, int) (G4ParticleHPProduct.cc:124)
==3495==    by 0xE653CA9: G4ParticleHPEnAngCorrelation::Sample(double) (G4ParticleHPEnAngCorrelation.cc:195)
==3495==    by 0xE62CF5C: G4ParticleHPCaptureFS::ApplyYourself(G4HadProjectile const&) (G4ParticleHPCaptureFS.cc:90)
==3495==    by 0xE6308D2: G4ParticleHPChannel::ApplyYourself(G4HadProjectile const&, int) (G4ParticleHPChannel.cc:308)
==3495==    by 0xE6265BC: G4ParticleHPCapture::ApplyYourself(G4HadProjectile const&, G4Nucleus&) (G4ParticleHPCapture.cc:141)
==3495==    by 0xE22B970: G4HadronicProcess::PostStepDoIt(G4Track const&, G4Step const&) (G4HadronicProcess.cc:350)
==3495==    by 0xD60DBB8: G4SteppingManager::InvokePSDIP(unsigned long) (G4SteppingManager2.cc:538)
==3495==    by 0xD60E05E: G4SteppingManager::InvokePostStepDoItProcs() (G4SteppingManager2.cc:510)

Alternative solution attached.
Comment 1 dennis.herbert.wright 2018-10-22 06:15:35 CEST
Fixed as prescribed.
Comment 2 Gabriele Cosmo 2018-11-15 15:47:15 CET
*** Problem 2077 has been marked as a duplicate of this problem. ***