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)

@hschindl, with the example uploaded, does the memory leak take place in your machine?

Hi,
sorry for the delay in getting back to you! No, I’m afraid I’ve not been able to reproduce the issue. I’ve used a slightly modified version of your example which I’ve attached. In your original example you had two places where you called EnablePlotting; which could explain why you saw an increase in memory usage with time even when you thought you had switched off plotting the drift lines.

When I switch off drift line visualisation (plotDrift = false), the memory consumption does not increase with the number of tracks simulated.

test.C (2.5 KB)

PS:

  • This isn’t directly related to you question, but I’ve also added a line (SetDistanceSteps) to set the target step size in AvalancheMC explicitly (to 0.1 mm, but this is something you might want to play with), because the default was giving strange results.
  • Also, again not directly related to your question, but just to point out a potential misunderstanding: AvalancheMC::DriftElectron simulates the drift of a single electron but does not simulate the secondaries produced in the avalanche. This might not be what you want.

@hschindl, thanks for your patient reply to my question, when using the code in the file of test.C, the error occured with the code: Sensor sensor(&cmp); it seems no proper constructor function. and when using codes: Sensor sensor; sensor.AddComponent(&cmp); the application can run, and the memory consumption problem is still exist. so something is wrong with my Garfield problem. by the way, AvalancheMicroscopic::DriftElectron can produced in the avalanche?

@hschindl, after updating the program, everything works well.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.