CRPropa / CRPropa3

CRPropa is a public astrophysical simulation framework for propagating extraterrestrial ultra-high energy particles. https://crpropa.github.io/CRPropa3/
https://crpropa.desy.de
GNU General Public License v3.0
72 stars 69 forks source link

Memory management in Variants #502

Open JulienDoerner opened 2 months ago

JulienDoerner commented 2 months ago

fixes #493:

The abstractConditions added a property to the candidate on the rejection. Up to now it only adds the key Rejected. I added the module name as the default Value for the flag.

Also the variant (in which this key is stored), does not have the right destructor. If it is deleted, the type of the variant was not passed to the clear function. Therefore no deletion of the variant was possible. This leaded to the bug in the memory consumption.

JulienDoerner commented 2 months ago

The error also occurred for setting a property to a candidate, but only if the property is of type STRING.

for i in range(10_000_000): 
  c = Candidate() 
  c.setProperty("k", "str")

will give the same issue as discussed before. With the explicit delete this issue is solved.

The only remaining point is related to the AssocVector.

Python gives the warning swig/python detected a memory leak of type 'Loki::AssocVector< std::string,crpropa::Variant > *', no destructor found. when running the following example:

 c = Candidate()
 c.properties 
 c.isActive() 

One solution could be to change the AssocVector to std::map which should have the same functionality, or does someone no a difference why we should keep the AssocVector?