[Issue 20651] New: Document that destructors may not allocate memory
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Mar 9 10:13:39 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20651
Issue ID: 20651
Summary: Document that destructors may not allocate memory
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: dlang.org
Assignee: nobody at puremagic.com
Reporter: default_357-line at yahoo.de
Consider the code from issue 20650:
class Foo { ~this() { new int; } }
void main() { new Foo; }
This runs into
core.exception.InvalidMemoryOperationError at src/core/exception.d(647): Invalid
memory operation .
The reason is that the GC may not be invoked during finalizers, ie. when
destructors are run. There is almost never a reason to do this; however, this
should still be documented in the language spec at
https://dlang.org/spec/class.html#destructors .
--
More information about the Digitalmars-d-bugs
mailing list