Bug 6203 – [GSoC] RefCounted (and clear()) doesn't call destructors of members of structs.

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-06-23T15:57:00Z
Last change time
2015-06-09T05:10:44Z
Assigned to
nobody
Creator
cristi.cobzarenco

Comments

Comment #0 by cristi.cobzarenco — 2011-06-23T15:57:31Z
Code: import std.typecons; import std.stdio; struct Enclosing { Member m; ~this() { writeln("Enclosing.~this()"); } } struct Member { ~this() { writeln("Member.~this()"); } } alias RefCounted!Enclosing Test; int main() { Test a; a.RefCounted.initialize(); return 0; } Outputs: Enclosing.~this() Member.~this() Enclosing.~this() The first two destructor calls are because of the call to initialize() which replaces the internal copy. The third one is called when 'a' goes out of scope. Unfortunately the destructor of 'a.m' is not called. This seems to be because of clear(): Code: int main() { Enclosing a; clear(a); return 0; } Output: Enclosing.~this() Enclosing.~this() Member.~this() The last two calls are when 'a' goes out of scope. The first one is on clear(), but as you can see it only calls the destructor of Enclosing. This causes memory leaks in my project, but that's about it. So it's not a blocker, but it's important for it to get fixed.
Comment #1 by cristi.cobzarenco — 2011-07-19T06:28:06Z
The cause is the same as in Issue 5667. *** This issue has been marked as a duplicate of issue 5667 ***