GC pathological case behaviour

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 28 12:24:07 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?

My bet is that you are creating fragmentation in the small size 
allocator. 10 000 is hitting the larg size one, whihc doesn't 
seems to have the same problem.

Now that would explain extra memory consumption, but I'm not sure 
why this wouldn't allow things to be freed at the end anyway.



More information about the Digitalmars-d mailing list