Adding pointers to GC with destructers
Freddy via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Apr 20 14:48:35 PDT 2015
On Monday, 20 April 2015 at 02:56:35 UTC, Ali Çehreli wrote:
> Not automatically. Check out addRange and addRoot:
>
> http://dlang.org/phobos/core_memory.html
>
> Ali
The destructor doesn't seem to be running
----
import std.stdio;
import std.c.stdlib;
import core.memory;
struct Test{
~this(){
writeln("free: ",&this);
free(&this);
}
}
void main(){
auto ptr=cast(Test*)malloc(4);
writeln("create: ",ptr);
GC.addRange(ptr,0,typeid(Test));
ptr=null;
GC.collect();
}
----
$ rdmd test
create: 1EEC730
More information about the Digitalmars-d-learn
mailing list