January 02, 2008 [Issue 1765] New: foreach scope does not call destructor | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=1765 Summary: foreach scope does not call destructor Product: D Version: 2.008 Platform: All OS/Version: All Status: NEW Keywords: wrong-code Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla@digitalmars.com ReportedBy: gide@nwawudu.com Foreach statement (without braces '{}') and scoping objects, prevents the call to the object's destructor. The code below outlines the problem. Code ---- module main; import std.stdio; class MyClass { public: this() { writefln("Constructor"); } ~this() { writefln("Destructor"); } private: int myNumber; }; int main() { writefln("1 - Start: OK dtor called"); foreach (a; new int[1]) { scope x = new MyClass; } writefln("1 - End: OK dtor called\n"); writefln("2 - Start: dtor NOT called"); foreach (a; new int[1]) scope x = new MyClass; writefln("2 - End: dtor NOT called\n"); return 0; }; Output ------ 1 - Start: OK dtor called Constructor Destructor 1 - End: OK dtor called 2 - Start: dtor NOT called Constructor 2 - End: dtor NOT called -- |
September 10, 2009 [Issue 1765] foreach scope does not call destructor | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1765 Don <clugdbug@yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |clugdbug@yahoo.com.au Resolution| |FIXED --- Comment #1 from Don <clugdbug@yahoo.com.au> 2009-09-10 14:17:41 PDT --- This was fixed in DMD2.032 (probably a side-effect of the fix for bug 2925). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation