www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7325] New: Static / instance destruction order

reply d-bugmail puremagic.com writes:
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



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: -------
Jan 20 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7325


timon.gehr gmx.ch changed:

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



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: -------
Jan 20 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7325


timon.gehr gmx.ch changed:

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



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: -------
Jan 20 2012