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

static array allocated on the heap does not call destructors on collection #20847

Open
schveiguy opened this issue Feb 10, 2025 · 0 comments
Open
Labels
Druntime:GC Issues relating the Garbage Collector Severity:safe @safe code

Comments

@schveiguy
Copy link
Member

A static array of structs with destructors does not call the finalizers on collection.

example:

struct S {
    ~this() {
        import std.stdio;
        writeln("dtor");
    }
}

void main() {
    auto arr = new S[1][1];
}
// no output

It is within spec to not guarantee destructors are called, but it is usually expected that if the memory allocated is collected (as it is in this case), the destructor will be called.

Imagine a case where a destructor removes its memory with some C library registry. If the dtor is not called but the memory is freed, then you have a dangling pointer still in the registry.

@schveiguy schveiguy added Severity:safe @safe code Druntime:GC Issues relating the Garbage Collector labels Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Druntime:GC Issues relating the Garbage Collector Severity:safe @safe code
Projects
None yet
Development

No branches or pull requests

1 participant