On Tue, 09 Sep 2014 16:13:24 +0000
Xaqq via Digitalmars-d-learn <[email protected]> wrote:

> Am I doing something wrong or is this a bug? Could someone please 
> try to explain?
ah, this is a very funny thing. you are using D dynamic array to keep
refcounted objects and by appending element to this array you are
hitting "array resizing". and from that moment everything goes wrong:
compiler needs to copy old array elements to new resized array. and
copying increases refcount. yet compiler doesn't know about this and
doesn't call destructors for copied elements (so refcount not
decreasing). this is perfectly ok for garbage-collected elements, but
completely wrong for refcounted elements.

to make a long story short: don't store RefCounted in dynamic arrays.
this will not work as expected yet.

Attachment: signature.asc
Description: PGP signature

Reply via email to