D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20651 - Document that destructors may not allocate memory
Summary: Document that destructors may not allocate memory
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dlang.org (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-09 10:13 UTC by FeepingCreature
Modified: 2024-12-15 15:25 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description FeepingCreature 2020-03-09 10:13:39 UTC
Consider the code from issue 20650:

class Foo { ~this() { new int; } }
void main() { new Foo; }

This runs into core.exception.InvalidMemoryOperationError@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 .
Comment 1 dlangBugzillaToGithub 2024-12-15 15:25:51 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dlang.org/issues/3982

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB