[Issue 2105] Manual Memory Management for Associative Arrays

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 19 11:47:06 PDT 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2105





------- Comment #5 from mmoncure at gmail.com  2008-05-19 13:47 -------
(In reply to comment #4)
> There really isn't much to it, but here's basically the canonical example:
> 
> import std.gc, std.stdio;
> 
> void main () {
>     uint count;
>     while(true) {
>         test();
>         fullCollect();
>         writefln(++count);
>     }
>     return;
> }
> 
> void test() {
>     scope uint[uint] foo;
>     for(uint i=0; i < 10_000_000; i++) {
>         foo[i]=i;
>     }
>     return;
> }
> 
> Basically, the only reference to foo goes out of scope on every cycle through
> the main loop, and should obviously be freed.  However, with each iteration,
> this program will use progressively more memory, even when fullCollect() is
> called explicitly.  This also happens with very large dynamic arrays, but this
> is less of a problem, since, at least for the simple cases, it's easy enough to
> just free them manually using the delete keyword.
> 
> Also note that I have tested this on 2.014 and it still happens, so I changed
> the version number.  

I tested the above program with both gdc v0.25 and dmd v1.028 on linux.  In
both cases the memory increased until the first insert loop completed and then
reached steady state (I dropped the iterations down a bit to make it more
obvious).  When I injected a sleep(1) after the gc collect, memory usage drop
back to baseline was noticeable in top with a low refresh interval.

Maybe this is a 2.0 bug??

merlin



-- 



More information about the Digitalmars-d-bugs mailing list