Garbage collection
James Gray
james.gray.public at gmail.com
Sat Jun 27 10:08:15 UTC 2020
I am writing a web application using vibe.d (not sure whether
that is relevant or not), and have run into a memory leak. I
wrote the following code to try and replicate the problem.
import std.algorithm;
import std.range;
import std.format;
import std.stdio;
import core.thread;
import core.memory;
auto f(R)(R r) {
return format("%s", r);
}
void main()
{
while(true)
{
writeln("Starting");
{
auto str = f(iota(100000000).map!(x=>x+1));
}
writeln("Done");
GC.collect();
Thread.sleep( dur!("msecs")( 30000 ) );
}
}
It doesn't replicate the problem but it still doesn't behave as
I would expect. I would expect the memory usage of this code to
grow and shrink. However, I find that the memory usage grows to
about 1.5GB and never decreases. Is there something I am not
understanding?
More information about the Digitalmars-d-learn
mailing list