I wrote the following program to test malloc/free:
import std.stdio;
import core.memory;
class ExternalMemoryHandle {
void *p;
this() {
p = GC.malloc(1024);
}
~this() {
GC.free(p);
}
}
void main() {
auto test = new ExternalMemoryHandle();
writeln("exiting");
}
The philosophy of this program is use class ExternalMemoryHandle as a handle
to some manually managed memory. If a ExternalMemoryHandle is constructed, it
alloc some memory. When this ExternalMemoryHandle is garbage collected, it
free those memory.
However it will fail with OutOfMemoryError. I got the following error when
running this program:
exiting
core.exception.OutOfMemoryError
What's wrong with this tiny program?