D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2925 - Destructor not called
Summary: Destructor not called
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P2 blocker
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2009-05-02 18:45 UTC by Andrei Alexandrescu
Modified: 2015-06-09 05:14 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrei Alexandrescu 2009-05-02 18:45:04 UTC
import std.stdio;

struct S {
    this(int x) {
        writefln("this(%s)", x);
        this.x = x;
    }
    this(this) {
        writefln("this(this) with %s", x);
    }
    ~this() {
        writefln("Going away S(%s)", x);
    }
    int x;
}

S fun1() {
    auto s = S(1);
    return s;
}

S fun2() {
    return S(2);
}

void main() {
    //auto s1 = fun1;
    auto s2 = fun2;
}

This example creates two objects but only destroys one. fun1 illustrates the correct behavior.
Comment 1 Walter Bright 2009-09-03 13:35:58 UTC
Fixed dmd 2.032