The memory leak occured when transporting electrons and ions using AvalancheMC class

I want to show the tracks of electrons and ions using AvalancheMC class. The key codes are:

AvalancheMC drift;
drift.SetSensor(&sensor);
drift.EnablePlotting(&driftView);
const unsigned int nTracks = 1;
  for (unsigned int j = 0; j < nTracks; ++j) {
    track.NewTrack(x0, y0, 0, 0, 0, 1, 0);
    std::cout<<"the total numbers of clusters is:   "<<track.GetClusters().size()<<std::endl;
    for (const auto& cluster : track.GetClusters()) {
        int num_electrons=cluster.n;
        std::cout<<"the total electron numbers of evergy cluster is:   "<<num_electrons<<std::endl;
        for(int jj=0;jj<num_electrons;jj++)
        {
            drift.DriftElectron(cluster.x,cluster.y,cluster.z,cluster.t);
            drift.DriftIon(cluster.x,cluster.y,cluster.z,cluster.t);
        }
    }
  }

when running the application, the memory leak occured.

by the way, the simple codes are:

AvalancheMC drift;
drift.SetSensor(&sensor);
drift.EnablePlotting(&driftView);
drift.DriftElectron(0.3,0.3,0,0);

with little probability, the codes worked; in most cases, the memory leak occured.

Thanks for reaching out! Let’s see what @hschindl think about this

Hi,
how did you diagnose the memory leak? Just the memory usage going up? When you enable plotting, ViewDrift stores internally the coordinates of all points along the drift lines, so if you have many, many drift lines you may indeed have a significant memory consumption.

The command “top“ was used, and the memory usage went up quickly, at the end, the application was killed.

by the way, when using AvalancheMicroscopic class, the application run well, and the tracks of electrons were drawn:

unnamed.pdf (1.5 MB)

by the way, when commenting out the codes about enable plotting:

// drift.EnablePlotting(&driftView);

the problem is still.

Can you prepare a minimal working example that reproduces the issue?

here is the example.

AvalancheMC.tar.gz (128.0 KB)