pass a delegate to an API as a context pointer?

Kirk McDonald kirklin.mcdonald at gmail.com
Tue Jul 3 01:24:22 PDT 2007


teo wrote:
> Kirk McDonald Wrote:
>> There is a serious problem with this. The garbage collector will not 
>> scan the C library for references. As far as it is concerned, that 
>> struct on the heap will have no references to it (assuming your program 
>> is more interesting than a single main() function, and this callback is 
>> being assigned in some function that returns), and it might be 
>> collected. Furthermore, if that delegate holds the only reference to 
>> that 'A' instance, it might be collected, too.
>>
>> You'll need to somehow keep a reference to that struct locally (that is, 
>> within your D code).
> 
> Is there any way to force the garbage collector to "cleanup", so I can experiment with it and see where  my software breaks? Perhaps I do have some weak references.
> 

Yes: std.gc.fullCollect()

-- 
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org



More information about the Digitalmars-d mailing list