Why is it a memory ERRO.
Dsby via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jan 29 04:43:53 PST 2016
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.
More information about the Digitalmars-d-learn
mailing list