Allocating delegate on heap?

Rick Mann rmann-d-lang at latencyzero.com
Mon Feb 19 13:11:49 PST 2007


Kirk McDonald Wrote:

> However, there's a very important detail which you should not overlook: 
> You are passing a pointer to GC-controlled data to a C library. The D 
> garbage collector doesn't scan the C library for references, so you will 
> need to keep a reference to any structs you pass to Carbon in your D 
> code. Otherwise, the GC will feel free to collect them when you least 
> expect it. This can be done with an AA:

Yes, thank you, I was aware of that. As it turns out, there's other stuff I need to do with my delegate that I can't do (namely, treat the .ptr portion of it as a pointer to a class derived from some interface Foo), so I ended up having to create a little class wrapper.

I add the class to the GC's root with std.gc.addRoot(). This should work, right (rather than storing it in an AA)?


More information about the Digitalmars-d-learn mailing list