Destructor call

2018-04-10 Thread n0fun via Digitalmars-d-learn
import std.stdio; struct S(alias n) { this(int) { throw new Exception("Exception"); } ~this() { writeln("destructor " ~ n); } } void main() { writeln("--- 1 ---"); try { auto s = S!"1"(0); } catch (Exception) {} writeln("--- 2 ---"); tr

Re: Destructor call

2018-04-10 Thread kinke via Digitalmars-d-learn
On Tuesday, 10 April 2018 at 18:34:54 UTC, n0fun wrote: Why the destructor is called in the second case and why not in the first? The first case is RAII, where destruction isn't done for not fully constructed instances. The second case is GC finalization at program shutdown and looks like a b

Re: Destructor call

2018-04-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, April 10, 2018 18:52:19 kinke via Digitalmars-d-learn wrote: > On Tuesday, 10 April 2018 at 18:34:54 UTC, n0fun wrote: > > Why the destructor is called in the second case and why not in > > the first? > > The first case is RAII, where destruction isn't done for not > fully constructed i

Re: Destructor call

2018-04-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/10/18 3:24 PM, Jonathan M Davis wrote: On Tuesday, April 10, 2018 18:52:19 kinke via Digitalmars-d-learn wrote: On Tuesday, 10 April 2018 at 18:34:54 UTC, n0fun wrote: Why the destructor is called in the second case and why not in the first? The first case is RAII, where destruction isn'

Missing destructor call using clear and base interface ref.

2012-08-06 Thread Roberto Delfiore
See the following code: interface A{ } class B : A{ this(string name){this.name = name;} ~this(){ writefln("Destructor %s", name); } string name; } void main(){ B b0 = new B("b0"); B b1 = new B("b1"); A a = b0; clear(a); clear(b1); } Output: Destru

Re: Missing destructor call using clear and base interface ref.

2012-08-06 Thread Ali Çehreli
On 08/06/2012 06:59 AM, Roberto Delfiore wrote: > See the following code: > > interface A{ > } > > class B : A{ > this(string name){this.name = name;} > ~this(){ > writefln("Destructor %s", name); > } > string name; > } > > void main(){ > B b0 = new B("b0"); > B b1 = new B("b1"); > > A a = b0; > c

Re: Missing destructor call using clear and base interface ref.

2012-08-09 Thread Roberto Delfiore
Thank you for your analysis, it's a very strange behavior. I still can not figure out if there is something I don't know or if it's is simply a bug. Good answer: Shouldn't destroy() work on an interface? On Monday, 6 August 2012 at 20:46:45 UTC, Ali Çehreli wrote: On 08/06/2012 06:59 AM, Robert

Re: Missing destructor call using clear and base interface ref.

2012-08-09 Thread Denis Shelomovskij
09.08.2012 12:36, Roberto Delfiore пишет: Thank you for your analysis, it's a very strange behavior. I still can not figure out if there is something I don't know or if it's is simply a bug. Good answer: Shouldn't destroy() work on an interface? Filled an issue: http://d.puremagic.com/issues/