Out of memory error (even when using destroy())

realhet via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 25 23:31:49 PDT 2017


Hi,

I'm kinda new to the D language and I love it already. :D So far 
I haven't got any serious problems but this one seems like beyond 
me.

import std.stdio;
void main(){
     foreach(i; 0..2000){
         writeln(i);
         auto st = new ubyte[500_000_000];
         destroy(st); //<-this doesnt matter
     }
}

Compiled with DMD 2.074.0 Win32 it produces the following output:
0
1
2
core.exception.OutOfMemoryError at src\core\exception.d(696): Memory 
allocation failed

It doesn't matter that I call destroy() or not. This is ok 
because as I learned: destroy only calls the destructor and marks 
the memory block as unused.

But I also learned that GC will start to collect when it run out 
of memory but in this time the following happens:
3x half GB of allocations and deallocations, and on the 4th the 
system runs out of the 2GB
  limit which is ok. At this point the GC already has 1.5GB of 
free memory but instead of using that, it returns a Memory Error. 
Why?

Note: This is not a problem when I use smaller blocks (like 50MB).
But I want to use large blocks, without making a slow wrapper 
that emulates a large block by using smaller GC allocated blocks.

Is there a solution to this?

Thank You!


More information about the Digitalmars-d-learn mailing list