www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - std.gc.disable not implemented or not working?

reply Paolo Invernizzi <arathorn NOSPAM_fastwebnet.it> writes:
Hi all,

DMD 0.159 win32, Why I don't see my memory exploding while the program 
is running?

If It's a bug, I'll add it to the collector.

int main(char[][] argv) {
     std.gc.disable();
     for (int i=0; i < 1000000; i++) {
         byte[] a = new byte[10000000];
     }
}

Thanks!

---
Paolo Invernizzi
May 31 2006
parent Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
Paolo Invernizzi wrote:
 Hi all,
 
 DMD 0.159 win32, Why I don't see my memory exploding while the program 
 is running?
 
 If It's a bug, I'll add it to the collector.
 
 int main(char[][] argv) {
     std.gc.disable();
     for (int i=0; i < 1000000; i++) {
         byte[] a = new byte[10000000];
     }
 }
A bit more detailed test: D:\Temp>cat test.d import std.stdio; import std.gc; class Big { uint nr; byte[10_000_000] lots_of_data; this(uint nr_) { nr = nr_; writefln(" construct ", nr); } ~this() { writefln("destruct ", nr); } } void main(char[][] argv) { std.gc.disable(); for (int i=0; i < 10; i++) { Big b = new Big(i); } writefln("Done."); } D:\Temp>dmd -run test.d construct 0 construct 1 construct 2 construct 3 destruct 3 construct 4 destruct 4 construct 5 destruct 5 construct 6 destruct 6 construct 7 destruct 7 construct 8 destruct 8 construct 9 Done. destruct 9 D:\Temp>dmd Digital Mars D Compiler v0.159 [[snip]] (So to answer your question, your memory doesn't explode because the gc isn't really disabled) And from the std.gc docs: void disable(); void enable(); disable() temporarilly disables garbage collection cycle, ... ... If the collector runs out of memory while it is disabled, it will throw an OutOfMemory exception. ... I'd say the collector clearly doesn't conform to that behavior, so yes, that would be a bug.
May 31 2006