free causes exception

Daniel Kozak via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jan 26 06:48:48 PST 2016


V Tue, 26 Jan 2016 14:20:29 +0000
Igor via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
napsáno:

> I have successfully malloc'ed an object but when I go to free it 
> in the destructor I get an exception. The destructor simply has
> 
> ~this() // destructor for Foo
> {
>      core.stdc.stdlib.free(&this);
> }
> 
> 
> auto buffer = core.stdc.stdlib.malloc(__traits(classInstanceSize, 
> App))[0..__traits(classInstanceSize, App)];
> auto app = cast(App)emplace!App(buffer[]);
> 
> I tried to retain a ptr to buffer and free that but still no 
> good. I also get a depreciation warning that &this is not an 
> lvalue. Hopefully I don't have to keep a ptr around to this 
> simply to free it and avoid future issues?
> 
> So how am I suppose to free an object?
> 
> 

core.stdc.stdlib.free(cast(void *)this);





More information about the Digitalmars-d-learn mailing list