Thread overview
[Issue 7325] New: Static / instance destruction order
Jan 20, 2012
Rene Zwanenburg
Jan 20, 2012
timon.gehr@gmx.ch
Jan 20, 2012
timon.gehr@gmx.ch
January 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7325

           Summary: Static / instance destruction order
           Product: D
           Version: unspecified
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: renezwanenburg@gmail.com


--- Comment #0 from Rene Zwanenburg <renezwanenburg@gmail.com> 2012-01-20 08:16:08 PST ---
We have a situation where a class has a static associative array member, which is accessed in the destructor.

If there are still instances left of this class during program shutdown, the GC deletes them and calls the destructor. At this point the static member appears to have been deleted, as any operations on the array cause the program to crash.

The aa is non-null, so checking for a null pointer doesn't work. As a workaround, it's possible to add a static destructor to the class which sets the aa to null, and check for this in the non-static destructor.

This is less than ideal, so it would be nice if it's possible to change the destruction order: First all class instances, then the static data.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7325


timon.gehr@gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr@gmx.ch


--- Comment #1 from timon.gehr@gmx.ch 2012-01-20 09:19:36 PST ---
That would break any code that accesses class instances or allocates memory from a static destructor.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7325


timon.gehr@gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


--- Comment #2 from timon.gehr@gmx.ch 2012-01-20 09:27:14 PST ---
The order of static destructors/GC is not what causes the problem: The AA is
invalidated by the GC shutting down, not by a static destructor.
If the order was changed, you'd still have the issue, but your solution would
not work anymore.

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