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

           Summary: [GSoC] Destructor not called on object returned by
                    method.
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: blocker
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: cristi.cobzare...@gmail.com


--- Comment #0 from Cristi Cobzarenco <cristi.cobzare...@gmail.com> 2011-08-15 
09:56:42 PDT ---
Program:
import std.stdio;

struct Bar {
    string m = "<not set>";

    this( string s ) { writeln( "Constructor - ", m = s ); }
    this( this )     { writeln( "Postblit    - ", m ); }
    ~this()          { writeln( "Destructor  - ", m ); }
    Bar bar()        { return Bar( "bar" ); }
}

Bar foo() { return Bar( "foo" ); }    

void main() {
    foo().bar();
}

Output:
Constructor - foo
Constructor - bar
Destructor  - foo

The object returned by bar() is not destroyed (leading to a memory leak in my
GSoC project). Calling bar() directly, rather than on the result returned by
foo() works properly. Saving the result of bar() in a named variable doesn't
fix  the problem (it creates three objects and destroys only two).

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

Reply via email to