Inexplicable invalid memory operation when program terminates

Lodovico Giaretta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Sep 5 10:42:18 PDT 2016


On Monday, 5 September 2016 at 17:33:17 UTC, pineapple wrote:
> I have a program which I have stripped down to a single 
> offending line which, when present in my program, causes an 
> invalid memory operation to occur after main has evaluated:
>
>     import mach.sdl.window;
>     void main(){
>         auto win = new Window(300, 300);
>     }
>
> The program is a bit larger than that, but I do not get the 
> error when I comment out that instantiation and the things 
> dependent on it.
>
> I commented out the body of the constructor that is being 
> called, and I still get the error.
>
> Am I missing something or is this an obnoxious bug with the GC?

InvalidMemoryOperationError is raised when you try to allocate 
memory inside a destructor called by the GC. I see from your 
repository that the destructor of Window uses a function called 
log defined by yourself. That function uses writeln internally. 
writeln is not @nogc, so it may be that that call to log in the 
destructor is actually allocating memory.


More information about the Digitalmars-d-learn mailing list