[Issue 2834] New: Struct Destructors are not called by the GC, but called on explicit delete.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Apr 14 06:00:50 PDT 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2834
Summary: Struct Destructors are not called by the GC, but called
on explicit delete.
Product: D
Version: 2.027
Platform: PC
OS/Version: Windows
Status: NEW
Keywords: spec
Severity: minor
Priority: P3
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: sandford at jhu.edu
According to the spec: [Struct] "Destructors are called when an object goes out
of scope. Their purpose is to free up resources owned by the struct object."
And while the heap is always 'in scope', it does delete structs which arguably
places them out of scope. Note that an explicit call to delete will run the
destructor. At a minimum, the spec should be updated to clearly reflect this
limitation. Since memory leaks, open files, etc will probably occur when a
struct with a postblit is manually allocated directly on the heap, instead of
on the stack or as part of an object, this issue might warrant a compiler
warning/error (i.e. an explicit cast is required).
--
More information about the Digitalmars-d-bugs
mailing list