Message: Memory Leak/Implementation of THitsCollection Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Sad Memory Leak/Implementation of THitsCollection 

Forum: Hits, Digitization and Pileup
Date: 09 May, 2012
From: Nicole Ackerman <Nicole Ackerman>

I closely followed (ie, copied the code from) example N02 for a sensitive detector and hits. I'm seeing a significant memory leak in my code that I can trace back to the THitsCollection via valgrind. I don't see the same behavior when I run valgrind on N02, but the only difference between my code and N02 is that I have two SD's. One is "nucSD" and the other is "cellSD". Hence, there are two THitsCollections being created (but with different names):

  trackerCollection = new NucHitsCollection
                          (SensitiveDetectorName,collectionName[0]);

SensitiveDetectorName is either nucSD or cellSD and collectionName is cellDet_collection or nucDet_collection.

I see that my two trackers don't occupy the same memory space on every event iteration (with the cell collection moving into the space previously occupied by the nuc collection):

@@@   NucSD: tracker SD Name: cellDet and CN: cellDet_collection
     trackerC: 0x13caea80
@@@   NucSD: tracker SD Name: nucDet and CN: nucDet_collection
     trackerC: 0x13caeaa0
Event number 0 processed.
@@@   NucSD: tracker SD Name: cellDet and CN: cellDet_collection
     trackerC: 0x13caeaa0
@@@   NucSD: tracker SD Name: nucDet and CN: nucDet_collection
     trackerC: 0x13caeac0
@@@   NucSD: tracker SD Name: cellDet and CN: cellDet_collection
     trackerC: 0x13caeac0
@@@   NucSD: tracker SD Name: nucDet and CN: nucDet_collection
     trackerC: 0x13caeae0
@@@   NucSD: tracker SD Name: cellDet and CN: cellDet_collection
     trackerC: 0x13caeae0
@@@   NucSD: tracker SD Name: nucDet and CN: nucDet_collection
     trackerC: 0x13caeb00
@@@   NucSD: tracker SD Name: cellDet and CN: cellDet_collection
     trackerC: 0x13caeb00
@@@   NucSD: tracker SD Name: nucDet and CN: nucDet_collection
     trackerC: 0x13caeb20
Events: 5

The memory leak increases with the number of events I run (the 24,000 bytes below is for 1000 events). Since the SD::Initialize command is called every event, I think I see why this is happening but not how to fix it. Should Geant be deleting the THitsCollection somewhere? Should I be choosing a specific naming convention to ensure that this happens? Do I need to explicitly delete or assign memory to these in a way that is different from N02? Memory management isn't my strength.

Part of the Valgrind output:

 24,000 bytes in 1,000 blocks are definitely lost in loss record 1,484 of 1,551
    at 0x4C28B35: operator new(unsigned long) (vg_replace_malloc.c:261)
    by 0x4E4F4B7: G4THitsCollection<NucHit>::G4THitsCollection(G4String, G4String) (G4THitsCollection.hh:142)
    by 0x4E4E745: NucSD::Initialize(G4HCofThisEvent*) (NucSD.cc:62)
    by 0x9501670: G4SDStructure::Initialize(G4HCofThisEvent*) (G4SDStructure.cc:208)
    by 0x95008A2: G4SDManager::PrepareNewEvent() (G4SDManager.cc:104)
    by 0x721F562: G4EventManager::DoProcessing(G4Event*) (G4EventManager.cc:148)
    by 0x721FF19: G4EventManager::ProcessOneEvent(G4Event*) (G4EventManager.cc:337)
    by 0x6FB9157: G4RunManager::DoEventLoop(int, char const*, int) (G4RunManager.cc:238)
    by 0x6FB7C68: G4RunManager::BeamOn(int, char const*, int) (G4RunManager.cc:143)
    by 0x6FC03C8: G4RunMessenger::SetNewValue(G4UIcommand*, G4String) (G4RunMessenger.cc:288)
    by 0xA8A471E: G4UIcommand::DoIt(G4String) (G4UIcommand.cc:210)
    by 0xA8B3795: G4UImanager::ApplyCommand(char const*) (G4UImanager.cc:411)
    by 0xA8B38E4: G4UImanager::ApplyCommand(G4String) (G4UImanager.cc:355)
    by 0xA897647: G4UIbatch::ExecCommand(G4String const&) (G4UIbatch.cc:167)
    by 0xA898464: G4UIbatch::SessionStart() (G4UIbatch.cc:212)
    by 0xA8B394B: G4UImanager::ExecuteMacroFile(char const*) (G4UImanager.cc:223)
    by 0xA8ABC53: G4UIcontrolMessenger::SetNewValue(G4UIcommand*, G4String) (G4UIcontrolMessenger.cc:268)
    by 0xA8A471E: G4UIcommand::DoIt(G4String) (G4UIcommand.cc:210)
    by 0xA8B3795: G4UImanager::ApplyCommand(char const*) (G4UImanager.cc:411)
    by 0xA8B38E4: G4UImanager::ApplyCommand(G4String) (G4UImanager.cc:355)
    by 0x40440C: main (flux.cc:105)

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: Memory Leak/Implementation of THitsCollection   (Tsukasa Aso - 14 May, 2012)
(_ More: Re: Memory Leak/Implementation of THitsCollection   (Nicole Ackerman - 14 May, 2012)
(_ Ok: Re: Memory Leak/Implementation of THitsCollection   (Nicole Ackerman - 15 May, 2012)
 Add Message Add Message
to: "Memory Leak/Implementation of THitsCollection"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]