local render_connection = RUN_SERVICE.PreRender:Connect(function(delta_time)
-- do stuff
end)
overhead_billboard.Destroying:Once(function()
render_connection:Disconnect()
end)
Will the engine garbage-collect render_connection after it’s disconnected? I have no further references to it, and setting it to nil makes the strict type solver mad, saying that Type 'nil' could not be converted into 'RBXScriptConnection', which is understandable since it doesn’t know it won’t be used later on.
Is it okay to leave it like this?
Thanks for reading
It will not be collected because there is still a variable you could access it through, but if you ever replace it by writing to the same variable, it can now be collected. Don’t listen to the linter when it complains about types, its just wrong.
it’ll be garbage collected when render_connection goes out of scope, because that’s when the upvalue referencing it is no longer accessible and marked for garbage collection.
it’ll also be garbage collected when the variable is reassigned, like azqjanna (no ping) said, because that’ll also cause the previous value to be inaccessible, and marked for cleaning.