[Issue 2834] Struct Destructors are not called by the GC, but called on explicit delete.

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Jul 4 20:43:57 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=2834

--- Comment #19 from Orvid King <blah38621 at gmail.com> ---
We still wouldn't be able to call the destructors in structs for arrays even 
with precise heap scanning, because we can't know that each value in the array 
is actually valid. Take for instance an array of File's, it's not valid to call 
the destructor of File.init, so we could compare the value of an element of an 
array of structs to it's init value, but who's to say that element was ever 
initialized in the first place? How would we detect that?

I think the best thing to do with the arrays of structs that have destructors 
is to simply make them illegal, and to present as an alternative, an array of a 
structure that you have defined and has an inner alias this to the original 
structure, but rather than having a destructor, has a named method that the 
user would have to call themselves for each element that they know is 
initialized.

--


More information about the Digitalmars-d-bugs mailing list