[Issue 6203] New: [GSoC] RefCounted (and clear()) doesn't call destructors of members of structs.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 23 16:02:20 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=6203

           Summary: [GSoC] RefCounted (and clear()) doesn't call
                    destructors of members of structs.
           Product: D
           Version: D1 & D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: cristi.cobzarenco at gmail.com


--- Comment #0 from Cristi Cobzarenco <cristi.cobzarenco at gmail.com> 2011-06-23 15:57:31 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list