destructors and GC again
Carlos Santander
csantander619 at gmail.com
Mon Oct 16 18:08:30 PDT 2006
Derek Parnell escribió:
> On Mon, 16 Oct 2006 15:34:22 -0500, Carlos Santander wrote:
>
>> There's also the problem with global objects:
>>
>> //-------------------------------------------
>> import std.stdio;
>>
>> class A
>> {
>> ~this()
>> {
>> writefln("~A");
>> }
>> }
>>
>> A tmp;
>>
>> void main()
>> {
>> tmp=new A;
>> }
>> //-------------------------------------------
>>
>> Nothing is printed.
>
> Yes, this is my experience too. It also happens with objects stored in AA's
> I think. However, either of these fix the issue.
>
> void main()
> {
> auto tmp=new A;
> }
>
> . . . .
>
> void main()
> {
> auto tmp=new A;
> scope(exit) { delete tmp; }
> }
>
Of course, but sometimes "tmp" has to be global, so it's not good all the time.
--
Carlos Santander Bernal
More information about the Digitalmars-d-learn
mailing list