Problem 792 - memory leak and other problems in G4GeneralParticleSource
Summary: memory leak and other problems in G4GeneralParticleSource
Status: RESOLVED LATER
Alias: None
Product: Geant4
Classification: Unclassified
Component: event (show other problems)
Version: 7.1
Hardware: All All
: P2 normal
Assignee: flei
URL:
Depends on:
Blocks:
 
Reported: 2005-09-09 12:42 CEST by jasondet
Modified: 2006-02-19 10:21 CET (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this problem.
Description jasondet 2005-09-09 12:42:16 CEST
I think I found a memory leak in G4GeneralParticleSource: whenever one calls
AddaSource(w), a new G4SingleParticleSource is allocated and the pointer to it
is pushed back into the sourceVector. If one then calls DeleteaSource(i) or
ClearAll(), the pointer is erased from sourceVector, but the memory for the
G4GeneralParticleSource it points to is never deallocated.

I also noticed that while ClearAll() clears the sourceProbability vector,
DeleteaSource(i) does not delete any entries in sourceProbability. This is
likely also a bug.

I recommend fixing DeleteaSource(i) to deallocate the memory for entry i before
erasing it, and to handle sourceProbability as well. Then I would recommend
rewriting ClearAll() to keep calling DeleteaSource(0) while sourceVector.size()
is non-zero so that the behavior of the two functions is always consistent.

Jason
Comment 1 flei 2005-09-29 04:41:59 CEST
The memory leak is very limited and will not cause too much a problem in most
simulations. Will look into this later.
Jason, it seems you may already have this fixed. If so can you send me your
correced code?

Fan