GC pathological case behaviour

luminousone via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 28 13:12:29 PDT 2016


On Tuesday, 28 June 2016 at 19:03:14 UTC, John Colvin wrote:
> On my machine (OS X), this program eats up memory with no end 
> in sight
>
> import std.concurrency;
> import core.stdc.stdio;
>
> void start()
> {
>     while(true)
>     {
>         receive(
>             (int msg)
>             {
>                 char[2] s = '\0';
>                 s[0] = cast(char)msg;
>                 puts(s.ptr);    // remove this => no memory leak
>             }
>         );
>     }
> }
>
>
> void main()
> {
>     auto hw_tid = spawn(&start);
>
>     while(true)
>     {
>         send(hw_tid, 64);
>         auto b = new ubyte[](1_000); // 10_000 => no memory leak
>     }
> }
>
> This is very odd, no? I'm not sure if it's a bug, but it sure 
> is surprising. Why should "puts" cause a GC leak (writeln is 
> the same)? What's so special about small allocations that 
> allows all my memory to get filled up?

Is puts high enough latency that, that main thread can fill the 
message queue faster then start can exhaust it? If you put a call 
to sleep for 1ms in the main loop does it have the same result?


More information about the Digitalmars-d mailing list