On Thursday, 24 October 2013 at 14:58:21 UTC, Rene Zwanenburg wrote:
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?

I answered a question related to RefCount on SO
http://stackoverflow.com/questions/4632355/making-a-reference-counted-object-in-d-using-refcountedt/4635050#4635050

Not written to your specific problem, but may give you the information you need.

Reply via email to