www.digitalmars.com         C & C++   DMDScript  

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

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: cristi.cobzarenco gmail.com



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: -------
Jun 23 2011
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6203


Cristi Cobzarenco <cristi.cobzarenco gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE



06:28:06 PDT ---
The cause is the same as in Issue 5667.

*** This issue has been marked as a duplicate of issue 5667 ***

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