fKill Secondary Particles

Greetings to the Geant4 Forum Team.

I’m new to Geant4 and for some time I’ve been facing a problem that I can’t seem to solve. I have a beryllium cylinder in which I have magnetic monopoles as primary particles. They interact with beryllium and produce secondary particles such as electrons and gamma. But when I want to use more than 100 events, the memory of the latpop is completely consumed and the simulation is killed automatically. From what I understand, to prevent this, it is necessary to kill the secondary particles. How could I do this? I tried to modify StackingAction.cc but there is no difference. So this is the default StakingAction.cc

 #include "StackingAction.hh"

 #include "G4Track.hh"

 StackingAction::StackingAction()
 {}

 StackingAction::~StackingAction()
 {}

 G4ClassificationOfNewTrack StackingAction::ClassifyNewTrack(const G4Track* track)
 {
   if (track->GetParentID()==0) return fUrgent;

else return fKill;		

  }

And I tried to modify with

#include "StackingAction.hh"

#include "G4Track.hh"

StackingAction::StackingAction()
{}

StackingAction::~StackingAction()
{}

 G4ClassificationOfNewTrack StackingAction::ClassifyNewTrack(const G4Track* track)
 {
    if (track->GetParentID()==0) return fUrgent; //keep primary particle

    else return fKill;		

    if (track->GetTrackID()!=0) return fKill //kill secondary particles
    else return fUrgent

  }

Can you guide me regarding this problem?Many Thanks!!!

Best regards,
Horea