Message: deleteaSource in General Particle Source Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None deleteaSource in General Particle Source 

Forum: Event and Track Management
Date: 14 Oct, 2010
From: Paola Marini <Paola Marini>

Hello,
  I'm not sure if this is the right place to post this problem, if not please tell me where I should write it.
However I'm running a simulation in which I need to call the General Particle Constructor inside my GeneratePrimaries() method. I delete it every time before to create a new one, first by deleteaSource (or CleanAll) and then deleting my GeneralParticleSource. Even if I do that I ended up filling the memory of my computer. I figured out that when I call deleteaSource (or CleanAll) it is deleting the pointer to the source but not the pointers to 
G4SPSPosDistribution
G4SPSAngDistribution
G4SPSEneDistribution
G4SPSRandomGenerator
because G4SingleParticleSource::~G4SingleParticleSource() is empty.
Is there a reason for which it has been built in such a way? Am I doing something wrong? (I cannot move the GPS constructor out of GeneratePrimaries)
I solved the problem by adding a method to my class:

void deleteArchitectCosmin(G4GeneralParticleSource* theArchitect) {
  if(theArchitect == NULL) return;
  for(G4int i=0;i<theArchitect->GetNumberofSource();i++) {
      theArchitect->SetCurrentSourceto(i);
      G4SingleParticleSource * source = 
	theArchitect->GetCurrentSource();
      G4SPSPosDistribution* del1 = source->GetPosDist();
      G4SPSAngDistribution* del2 = source->GetAngDist();
      G4SPSEneDistribution* del3 = source->GetEneDist();
      G4SPSRandomGenerator* del4 = source->GetBiasRndm();
      delete del1; delete del2; delete del3; delete del4;
      delete source;
  } 
  theArchitect->ClearAll();
  delete theArchitect;
}

but maybe you could simply add in G4SingleParticleSource::~G4SingleParticleSource() the destructors of those three objects.
G4SingleParticleSource::~G4SingleParticleSource() {
  delete GetPosDist();
  delete GetAngDist();
  delete GetEneDist();
  delete GetBiasRndm();
}   

Is there an other way to solve my problem? Thank you very much for your help Paola

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

1 Feedback: Re: deleteaSource in General Particle Source   (Gumplinger Peter - 14 Oct, 2010)
 Add Message Add Message
to: "deleteaSource in General Particle Source"

 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 ]