[Issue 9335] Dtors are not called for dynamic arrays initialized by literals

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jan 17 08:39:32 PST 2013


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


monarchdodra at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra at gmail.com
           See Also|                            |http://d.puremagic.com/issu
                   |                            |es/show_bug.cgi?id=9334


--- Comment #1 from monarchdodra at gmail.com 2013-01-17 08:39:31 PST ---
(In reply to comment #0)
> Dynamic arrays of structs initialized by array literals go out of scope without
> calling destructors. This does not happen with static arrays.
> 
> import std.stdio : writefln;
> 
> struct S
> {
>     int i;
>     this(this) { writefln("%X postbit", i); i = 0;}
>     ~this() { writefln("%X dtor", i); }
> }
> 
> void main()
> {
>     S[] arr = [S()];
> }
> 
> Issue is maked as dmd issue, because druntime cannot call destructors when AA
> array goes out of the scope.

Same answer as in http://d.puremagic.com/issues/show_bug.cgi?id=9334.

The array is allocated dynamically, and makes no promises it will release at
the end of the scope, or of the program.

I'm not sure what you mean by "array literals", but you'll get the same
behavior with:
S[] arr = new S[](5);

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


More information about the Digitalmars-d-bugs mailing list