I want my Memory back ;-)

Nick Sabalausky a at a.a
Tue Jul 13 11:19:35 PDT 2010


"Nick Sabalausky" <a at a.a> wrote in message 
news:i1iaan$1nbe$1 at digitalmars.com...
> "ABothe" <info at asdf.com> wrote in message 
> news:i1hf3h$7sd$1 at digitalmars.com...
>> So there isn't any other method than calling C's free(); or malloc
>> (); ?
>
> GC.minimize() should do it:
>
> http://www.digitalmars.com/d/2.0/phobos/std_gc.html
>
> If it doesn't, then there's probably something holding on a reference to 
> it (like the LRU cache Steven mentioned), or something that the GC 
> mistakenly thinks is a reference to it.
>

But, in a GC'ed environment, you shouldn't normally be trying to release 
memory back to the OS every time you delete something. In most cases, the GC 
deliberately saves freed memory to return it back to you the next time you 
allocate. So if you want to see whether or not you're *really* leaking, try 
something more like this:

while(true)
{
    byte[] asdf=new byte[50_000_000];
    GC.free(cast(void*) asdf.ptr);
}

Then monitor the memory usage reported by the OS. If it keeps climbing 
higher and higher and higher, then something's going wrong. If it stays 
pretty much constant, then everything's working correctly.




More information about the Digitalmars-d mailing list