Why is it a memory ERRO.
Dsby via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jan 29 04:47:43 PST 2016
On Friday, 29 January 2016 at 12:43:53 UTC, Dsby wrote:
> the Code:
> class MyClass
> {
> this(){
> by = new ubyte[10000];
> ++i;
> }
> ~this(){
> GC.free(by.ptr);
> by = null;
> writeln("free");
> }
> void show(){
> writeln(i);
> };
> private:
> ubyte[] by;
> static i = 0;
> };
>
> void main()
> {
> bool start = true;
> int i = 0;
> while(start){
> auto obj = new MyClass();
> obj.show();
> Thread.sleep(5.msecs);
> //obj.destroy;
> //GC.free(cast(void *)obj);
> ++i;
> if (i > 20000)
> break;
> }
> }
>
> the code will be :
> 341
> core.exception.InvalidMemoryOperationError at src/core/exception.d(679): Invalid memory operation
> ----------------
> core.exception.InvalidMemoryOperationError at src/core/exception.d(679): Invalid memory operation
> ----------------
>
> .why is it?
> if < obj.destroy; > is exec. the code will not errno.
I am in 2.069, on opensuse leap 42.1 X86_64
dmd -v
DMD64 D Compiler v2.069
Copyright (c) 1999-2015 by Digital Mars written by Walter Bright
More information about the Digitalmars-d-learn
mailing list