Skip to content

Clean up signals when Luau reports signal GC#705

Open
Sleitnick wants to merge 3 commits intomainfrom
bugfix/signal-fixes
Open

Clean up signals when Luau reports signal GC#705
Sleitnick wants to merge 3 commits intomainfrom
bugfix/signal-fixes

Conversation

@Sleitnick
Copy link
Member

Previous behavior: Signals remained partially alive until the attached GameObject was destroyed. This is essentially a mem leak, as the resource is no longer needed but is staying around.

const conn = button.onClick.Connect(() => {
    conn.Disconnect();
    // 'onClick' is created and now exists for the remainder of 'button' gameObject's
    // lifetime even though 'conn' is disconnected. This includes both resources in Luau and in C#.
});

New behavior: Luau reports to C# when a Luau signal is GC'd, thus allowing C# to clean up C#-based signal resources once no longer needed. There are also various fixes on the Luau side that address signals being pinned longer than they should.

const conn = button.onClick.Connect(() => {
    conn.Disconnect();
    // 'onClick' can be safely GC'd on the Luau side (no connections active). C# resources are cleaned up.
});

No change required from anyone. These changes are opaque in nature, mostly on the Luau plugin side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant