Memory leak in rare cases using foreach and parallel
Guillaume Lathoud
gsub at glat.info
Mon Oct 14 06:52:32 UTC 2019
Hello,
In a number-crunching app that tries many different configuration
parameters, I observed in some rare cases a memory leak when
doing:
class Cfg { /* ...configuration parameters...*/ }
auto cfg_range; // range that spits out the many
configurations (instances of Cfg)
foreach (cfg; parallel( cfg_range ))
{
// Do one computation for the set of parameters `cfg`
}
using LDC 1.10.0 (based on dmd 2.080.1) on a linux machine.
This was difficult to reduce to a simple use case. The memory
leak happened in rare cases, but in those cases, it always
happened.
The workaround I found looked like this:
foreach (i; parallel( cfg_range.length.iota ))
{
auto cfg = cfg_range[ i ];
// Do one computation for the set of parameters `cfg`
}
Hopefully this helps anyone encountering a similar issue and/or
LDC developers.
Best regards,
Guillaume
More information about the digitalmars-d-ldc
mailing list