digitalmars.D.bugs - [Issue 20379] New: Cannot destroy associative arrays AAs (Destructor
- d-bugmail puremagic.com (51/51) Nov 10 2019 https://issues.dlang.org/show_bug.cgi?id=20379
https://issues.dlang.org/show_bug.cgi?id=20379 Issue ID: 20379 Summary: Cannot destroy associative arrays AAs (Destructor not called on values) Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: major Priority: P1 Component: druntime Assignee: nobody puremagic.com Reporter: johannespfau gmail.com Tested with 2.089: ------------------------------------------------- import std.stdio; struct Test { ~this(){writefln("~this %x", &this);} } void main() { Test[int] cache; cache[0] = Test(); writeln("destroy"); destroy(cache); writeln(cache); writeln("destroyed"); } ------------------------------------------------- destroy [] destroyed ~this 7f521c9d8004 This breaks deterministic destruction (e.g. of reference counted objects). Replacing destroy with this: ------------------------------------------------- foreach(key, ref val; cache) destroy(val); cache = null; ------------------------------------------------- destroy ~this 7f9b3f65d004 [] destroyed ~this 7f9b3f65d004 So this can be used as a workaround for types which do not mind being destructed to often, such as Reference Counted Types. For all other types, this will double-destruct it. --
Nov 10 2019