OpenGATE / Gate

Official public repository of Gate
http://www.opengatecollaboration.org
GNU Lesser General Public License v3.0
236 stars 263 forks source link

vGate9.3 maybe with memory leak #615

Closed Fantasticlyy closed 1 year ago

Fantasticlyy commented 1 year ago

Describe the bug use the vGate 9.3,while use digitizer and enable the “/gate/output/” ,when run a simulation ,the RAM will be raise by follow time,I thin may be enable the “/gate/output/” with memory leak,this issue only appear in vGate9.3 ,the other version not appear. Desktop (please complete the following information): vGate9.3 VirtualBox 7.06

#############

DIGITIZER

############# /gate/digitizerMgr/name LESingles /gate/digitizerMgr/chooseSD pixel /gate/digitizerMgr/insert SinglesDigitizer /gate/digitizerMgr/pixel/SinglesDigitizer/LESingles/setInputCollection Singles /gate/digitizerMgr/pixel/SinglesDigitizer/LESingles/insert energyFraming /gate/digitizerMgr/pixel/SinglesDigitizer/LESingles/energyFraming/setMin 0. keV /gate/digitizerMgr/pixel/SinglesDigitizer/LESingles/energyFraming/setMax 6000. keV

########

OUTPUT

######## /gate/output/tree/enable /gate/output/tree/addFileName output/LHCsI.txt /gate/output/tree/hits/enable
/gate/output/tree/addCollection LESingles /gate/output/tree/addCollection Singles

tontyoutoure commented 1 year ago

Can confirm. I ran valgrind and the following part is what increases as duration of simulation increase:

parts of valgrind output ``` ==72618== 2,844,528 bytes in 118,522 blocks are definitely lost in loss record 22,855 of 22,861 ==72618== at 0x483BE63: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==72618== by 0x359D45: __gnu_cxx::new_allocator::allocate(unsigned long, void const*) (new_allocator.h:114) ==72618== by 0x358F84: std::allocator_traits >::allocate(std::allocator&, unsigned long) (alloc_traits.h:443) ==72618== by 0x3584AD: std::_Vector_base >::_M_allocate(unsigned long) (stl_vector.h:343) ==72618== by 0x37E712: std::_Vector_base >::_M_create_storage(unsigned long) (stl_vector.h:358) ==72618== by 0x37E1CA: std::_Vector_base >::_Vector_base(unsigned long, std::allocator const&) (stl_vector.h:302) ==72618== by 0x3A0AFA: std::vector >::vector(unsigned long, int const&, std::allocator const&) (stl_vector.h:521) ==72618== by 0x3A0203: GateOutputVolumeID::GateOutputVolumeID(unsigned long) (GateOutputVolumeID.hh:56) ==72618== by 0x417BA6: GateDigi::GateDigi(void const*) (GateDigi.cc:45) ==72618== by 0x5F2AC7: GateReadout::Digitize() (GateReadout.cc:225) ==72618== by 0x42AC40: GateDigitizerMgr::RunDigitizers() (GateDigitizerMgr.cc:427) ==72618== by 0x3833AA: GateAnalysis::RecordEndOfEvent(G4Event const*) (GateAnalysis.cc:479) ==72618== ==72618== 2,844,552 bytes in 118,523 blocks are definitely lost in loss record 22,856 of 22,861 ==72618== at 0x483BE63: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==72618== by 0x359D45: __gnu_cxx::new_allocator::allocate(unsigned long, void const*) (new_allocator.h:114) ==72618== by 0x358F84: std::allocator_traits >::allocate(std::allocator&, unsigned long) (alloc_traits.h:443) ==72618== by 0x3584AD: std::_Vector_base >::_M_allocate(unsigned long) (stl_vector.h:343) ==72618== by 0x37E712: std::_Vector_base >::_M_create_storage(unsigned long) (stl_vector.h:358) ==72618== by 0x37E1CA: std::_Vector_base >::_Vector_base(unsigned long, std::allocator const&) (stl_vector.h:302) ==72618== by 0x3A0AFA: std::vector >::vector(unsigned long, int const&, std::allocator const&) (stl_vector.h:521) ==72618== by 0x3A0203: GateOutputVolumeID::GateOutputVolumeID(unsigned long) (GateOutputVolumeID.hh:56) ==72618== by 0x417BA6: GateDigi::GateDigi(void const*) (GateDigi.cc:45) ==72618== by 0x61C6F8: GateSpatialResolution::Digitize() (GateSpatialResolution.cc:115) ==72618== by 0x42AC40: GateDigitizerMgr::RunDigitizers() (GateDigitizerMgr.cc:427) ==72618== by 0x3833AA: GateAnalysis::RecordEndOfEvent(G4Event const*) (GateAnalysis.cc:479) ==72618== ==72618== 2,844,624 bytes in 118,526 blocks are definitely lost in loss record 22,857 of 22,861 ==72618== at 0x483BE63: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==72618== by 0x359D45: __gnu_cxx::new_allocator::allocate(unsigned long, void const*) (new_allocator.h:114) ==72618== by 0x358F84: std::allocator_traits >::allocate(std::allocator&, unsigned long) (alloc_traits.h:443) ==72618== by 0x3584AD: std::_Vector_base >::_M_allocate(unsigned long) (stl_vector.h:343) ==72618== by 0x37E712: std::_Vector_base >::_M_create_storage(unsigned long) (stl_vector.h:358) ==72618== by 0x37E1CA: std::_Vector_base >::_Vector_base(unsigned long, std::allocator const&) (stl_vector.h:302) ==72618== by 0x3A0AFA: std::vector >::vector(unsigned long, int const&, std::allocator const&) (stl_vector.h:521) ==72618== by 0x3A0203: GateOutputVolumeID::GateOutputVolumeID(unsigned long) (GateOutputVolumeID.hh:56) ==72618== by 0x417BA6: GateDigi::GateDigi(void const*) (GateDigi.cc:45) ==72618== by 0x48549F: GateEnergyResolution::Digitize() (GateEnergyResolution.cc:96) ==72618== by 0x42AC40: GateDigitizerMgr::RunDigitizers() (GateDigitizerMgr.cc:427) ==72618== by 0x3833AA: GateAnalysis::RecordEndOfEvent(G4Event const*) (GateAnalysis.cc:479) ==72618== ==72618== 2,844,696 bytes in 118,529 blocks are definitely lost in loss record 22,858 of 22,861 ==72618== at 0x483BE63: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==72618== by 0x359D45: __gnu_cxx::new_allocator::allocate(unsigned long, void const*) (new_allocator.h:114) ==72618== by 0x358F84: std::allocator_traits >::allocate(std::allocator&, unsigned long) (alloc_traits.h:443) ==72618== by 0x3584AD: std::_Vector_base >::_M_allocate(unsigned long) (stl_vector.h:343) ==72618== by 0x37E712: std::_Vector_base >::_M_create_storage(unsigned long) (stl_vector.h:358) ==72618== by 0x37E1CA: std::_Vector_base >::_Vector_base(unsigned long, std::allocator const&) (stl_vector.h:302) ==72618== by 0x3A0AFA: std::vector >::vector(unsigned long, int const&, std::allocator const&) (stl_vector.h:521) ==72618== by 0x3A0203: GateOutputVolumeID::GateOutputVolumeID(unsigned long) (GateOutputVolumeID.hh:56) ==72618== by 0x417BA6: GateDigi::GateDigi(void const*) (GateDigi.cc:45) ==72618== by 0x37C84A: GateAdder::Digitize() (GateAdder.cc:70) ==72618== by 0x42AC40: GateDigitizerMgr::RunDigitizers() (GateDigitizerMgr.cc:427) ==72618== by 0x3833AA: GateAnalysis::RecordEndOfEvent(G4Event const*) (GateAnalysis.cc:479) ==72618== ==72618== 2,844,696 bytes in 118,529 blocks are definitely lost in loss record 22,859 of 22,861 ==72618== at 0x483BE63: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==72618== by 0x359D45: __gnu_cxx::new_allocator::allocate(unsigned long, void const*) (new_allocator.h:114) ==72618== by 0x358F84: std::allocator_traits >::allocate(std::allocator&, unsigned long) (alloc_traits.h:443) ==72618== by 0x3584AD: std::_Vector_base >::_M_allocate(unsigned long) (stl_vector.h:343) ==72618== by 0x37E712: std::_Vector_base >::_M_create_storage(unsigned long) (stl_vector.h:358) ==72618== by 0x37E1CA: std::_Vector_base >::_Vector_base(unsigned long, std::allocator const&) (stl_vector.h:302) ==72618== by 0x3A0AFA: std::vector >::vector(unsigned long, int const&, std::allocator const&) (stl_vector.h:521) ==72618== by 0x3A0203: GateOutputVolumeID::GateOutputVolumeID(unsigned long) (GateOutputVolumeID.hh:56) ==72618== by 0x417BA6: GateDigi::GateDigi(void const*) (GateDigi.cc:45) ==72618== by 0x483461: GateEnergyFraming::Digitize() (GateEnergyFraming.cc:86) ==72618== by 0x42AC40: GateDigitizerMgr::RunDigitizers() (GateDigitizerMgr.cc:427) ==72618== by 0x3833AA: GateAnalysis::RecordEndOfEvent(G4Event const*) (GateAnalysis.cc:479) ```

After a while I realize the cause of the problem is kind simple. A lot of digitizer ( not sure if it's all of them) said

GateDigi* inputDigi = new GateDigi();

in their ::Digitize() method. And without delete.

It could be patched with ease.

tontyoutoure commented 1 year ago

Wow it turn outs that this pointer will be assigned other values and should not allocate anything in the first place. Make a PR hope it will be merged asap.

tontyoutoure commented 1 year ago

It seems there are more leak other than the one showed above. I'll try to find it.

Edit: Turns out to be it's something else. The fix above should be sufficient.

tontyoutoure commented 1 year ago

You can now git pull origin develop in your virtual machine ~/Software/Gate/src dir and make in ~/Software/Gate/bin dir to fix the problem. @Fantasticlyy

dsarrut commented 1 year ago

done #619