Bug 12256 – Neither arrays nor associative arrays finalize their data

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-02-25T15:36:05Z
Last change time
2018-11-23T11:25:34Z
Assigned to
No Owner
Creator
rswhite4

Comments

Comment #0 by rswhite4 — 2014-02-25T15:36:05Z
I expect this is an known issue but we may should fix this: ---- import std.stdio; struct Foo { this(this) { writeln("Copy"); } ~this() { writeln("DTor"); } } void main() { Foo[] fs; fs ~= Foo(); Foo[int] fas; fas[42] = Foo(); // Even this doesn't change anything //destroy(fas); //destroy(fs); } ---- You will never see "DTor". But if you work with ref count or C memory you would hope and expect that your data is finalized. So, the compiler should finalize the data if they is collected. Unfortunately I expect that we need a precise GC for that? IMO the current behaviour is unexpected and bug prone. As _workaround_ it would be helpful if destroy would work that way, but currently it doesn't.
Comment #1 by safety0ff.bugz — 2014-02-25T16:03:57Z
Somewhat of a duplicate of issue #9335.
Comment #2 by stanislav.blinov — 2018-11-23T11:25:34Z
Since 2.067 the array is getting finalized. Since 2.068 so is the associative array. Note, however, that destroy() doesn't destruct individual elements, but there's a separate issue for that (issue 12274).