On Mon, 10 Nov 2014 08:10:08 +0000 Tomer Filiba via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> The following code does not invoke S.~this. If I change `struct > S` to `class S` - it does. Memory consumption remains constant, > meaning memory is collected, but destructors are not called. > > import std.stdio; > import std.conv; > > struct S { > string s; > > ~this() { > writeln("~S"); > } > } > > void main() { > auto i = 0; > S[] arr; > > while (true) { > arr ~= S("hello " ~ text(i++)); > if (arr.length == 1_000_000) { > writeln(&arr[8888], " = ", arr[8888].s); > arr.length = 0; > } > } > } > > > Is it a bug? How can I effectively implement RAII with this > behavior? it's a bug, it was recently filled and Walter (afair) made a PR with fix, but it's not yet merged. > Any workaround for this? made your own array implementation which manually calls dtors. or wait for next DMD release with this bug fixed. ;-)
signature.asc
Description: PGP signature