Bug in RefCounted?

Rene Zwanenburg renezwanenburg at gmail.com
Thu Oct 24 07:58:20 PDT 2013


I'm writing a D wrapper for a C library. I was planning to use 
RefCounted structs to control the lifetime of objects created by 
this library. Please check the following example:

http://dpaste.dzfl.pl/b49962bf

Foo would be an opaque struct. createFoo() and destroyFoo() would 
be implemented in the C library (I know I have to declare them 
extern(C), this is just an example).

As you can see, that code prints 'Destroying Foo' twice, with 
different pointers. I expected destroyFoo to be called only once, 
on the instance created by createFoo(), when the Bar instance 
goes out of scope. Current behaviour causes an invalid pointer to 
be passed to destroyFoo(). Is this a bug in RefCounted or am I 
doing something wrong?


More information about the Digitalmars-d-learn mailing list