Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document that destructors may not allocate memory #3982

Open
dlangBugzillaToGithub opened this issue Mar 9, 2020 · 0 comments
Open

Document that destructors may not allocate memory #3982

dlangBugzillaToGithub opened this issue Mar 9, 2020 · 0 comments

Comments

@dlangBugzillaToGithub
Copy link

FeepingCreature (@FeepingCreature) reported this on 2020-03-09T10:13:39Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=20651

Description

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 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant