[Issue 18900] New: GC doesn't collect large arrays on 32-bit Windows

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed May 23 21:03:19 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=18900

          Issue ID: 18900
           Summary: GC doesn't collect large arrays on 32-bit Windows
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: dkorpel at live.nl

I was loading into memory an processing a bunch of large (~130 Mb) files
sequentially and got an out of memory error after about 10. I reduced it to
this test code:

```
import std.stdio;
import core.memory: GC;

enum Mb = 1024*1024;
void main(string[] args) {
        foreach(i; 0..10) {
                auto data = new ubyte[12*Mb];
                writefln("GC used: %d Mb / %d Mb", GC.stats.usedSize/Mb,
(GC.stats.freeSize+GC.stats.usedSize)/Mb);
        }
        writeln("Collecting");
        GC.collect();
        writefln("GC used: %d Mb / %d Mb", GC.stats.usedSize/Mb,
(GC.stats.freeSize+GC.stats.usedSize)/Mb);
}
```
When compiling on Windows with `dmd -m32` it results in:
```
GC used: 100 Mb / 150 Mb
GC used: 200 Mb / 300 Mb
GC used: 300 Mb / 450 Mb
GC used: 400 Mb / 600 Mb
GC used: 500 Mb / 750 Mb
GC used: 600 Mb / 900 Mb
GC used: 700 Mb / 1050 Mb
GC used: 800 Mb / 1200 Mb
GC used: 900 Mb / 1350 Mb
GC used: 1000 Mb / 1500 Mb
Collecting
GC used: 1000 Mb / 1500 Mb
```

With -m64 it collects just fine and doesn't go over 200 Mb. 
When the array is 10 Mb, it also collects just fine on 32-bit leaving 0 Mb used
in the end, but with 11 Mb arrays it ends at 22 Mb used and with 12 Mb arrays
it ends at 132 Mb used.

Looking around if someone else had this problem, I found this thread: 
https://forum.dlang.org/post/l3e6jn$cuu$1@digitalmars.com
Mentioning "If your programm is a 32-bit application the GC most likely leaks
memory because it thinks its still referenced.". 

I don't know exactly why 32-bit applications complicates checking whether
something is referenced, but if this can be fixed that would be nice.

--


More information about the Digitalmars-d-bugs mailing list