Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
April 19, 2007 [Issue 1164] New: Wrong order of memory deallocation | ||||
---|---|---|---|---|
| ||||
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. -- |
April 19, 2007 [Issue 1164] Wrong order of memory deallocation | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | 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." -- |
April 19, 2007 Re: [Issue 1164] Wrong order of memory deallocation | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | 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) |
April 19, 2007 Re: [Issue 1164] Wrong order of memory deallocation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marcin Kuszczak | "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. |
April 20, 2007 [Issue 1164] Wrong order of memory deallocation | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | 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 | -- |
April 20, 2007 [Issue 1164] Wrong order of memory deallocation | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | 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. -- |
April 20, 2007 [Issue 1164] Wrong order of memory deallocation | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | 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; } -- |
Copyright © 1999-2021 by the D Language Foundation