www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1164] New: Wrong order of memory deallocation

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1164

           Summary: Wrong order of memory deallocation
           Product: D
           Version: 1.012
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: aarti interia.pl


class Storage {
    void sync() {};
}
class Test {
    Storage s;
    this() {s=new Storage;}
    ~this() {s.sync();}
}
void main() {
    new Test;
}

Code above triggers Segmentation fault. Didn't test it on Windows, but probably
it is not platform specific issue.


-- 
Apr 19 2007
next sibling parent reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1164


deewiant gmail.com changed:

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




------- Comment #1 from deewiant gmail.com  2007-04-19 14:10 -------
Invalid. http://www.digitalmars.com/d/class.html#destructors has the following
passage:

"When the garbage collector calls a destructor for an object of a class that
has members that are references to garbage collected objects, those references
are no longer valid. This means that destructors cannot reference sub objects.
This rule does not apply to auto objects or objects deleted with the
DeleteExpression."


-- 
Apr 19 2007
parent reply Marcin Kuszczak <aarti interia.pl> writes:
d-bugmail puremagic.com wrote:

 
 "When the garbage collector calls a destructor for an object of a class
 that has members that are references to garbage collected objects, those
 references are no longer valid. This means that destructors cannot
 reference sub objects. This rule does not apply to auto objects or objects
 deleted with the DeleteExpression."
 

Hmmm... but it doesn't help much with cleaning up on destruction. When collecting would be done in two phases (1. calling all destructors, 2. deallocating memory) maybe it would work. Maybe I should mark it as enhancement? -- Regards Marcin Kuszczak (Aarti_pl)
Apr 19 2007
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Marcin Kuszczak" <aarti interia.pl> wrote in message 
news:f08g87$icb$1 digitalmars.com...
 d-bugmail puremagic.com wrote:


 Maybe I should mark it as enhancement?

I would. I've never understood the whole "never know when / if dtors will be called" thing. It's just plain irritating, because face it, sometimes you _do_ need to destroy things (like non-memory resources) when an object is collected.
Apr 19 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1164


aarti interia.pl changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |




-- 
Apr 19 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1164





------- Comment #3 from aarti interia.pl  2007-04-20 01:50 -------
Reopened and marked as enhancement.


-- 
Apr 19 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1164





------- Comment #4 from ddparnell bigpond.com  2007-04-20 02:20 -------
It also fails in Windows.

The workaround is to use the 'scope' attribute.

void main()
{
  scope Test t = new Test;
}


-- 
Apr 20 2007