Let the thread yields created through RBXScriptSignal::Wait gc when the signal is destroyed

Currently as a Roblox developer it is difficult to code without using RBXScriptSignal::Wait in scenarios where the thread may not resume. Having memory leaks because of Roblox’s implementation frustrates me and may make thousands of developers spend millions of hours debugging their own code in search of the issue


The reason for posting this as a feature request and not a bug report is because it seems to have been known for 3+ years

You can see that it does not gc from the following code samples (first shows that threads with no references that indefinitely yield can gc, and the second shows that RBXScriptSignal::Wait leaks)

wait(2)
print(collectgarbage'count')
for i=1,1e5 do
	coroutine.wrap(function()coroutine.yield()end)()
end
warn(collectgarbage'count')
while wait() do print(collectgarbage'count') end
wait(2)
local sig=Instance.new'BindableEvent'
print(collectgarbage'count')
for i=1,1e5 do
	coroutine.wrap(function()sig.Event:Wait()end)()
end
warn(collectgarbage'count')
sig:Destroy()
sig=nil
while wait() do print(collectgarbage'count') end
9 Likes