Hello, I’m still a little confused on the GC behavior of goodsignal, it might be general lua GC behavior, but for some reason cyclic references are causing the GC to not collect things.
Here is an example to show this:
local Weak = require(script.Parent.ModuleScript)
local Table = {
Event = require(game.ServerScriptService.Signal).new()
}
Table.Event:Connect(function()
print(Table)
end)
Weak[2] = Table
Here’s my test for checking if the table has been GCed
local Weak = setmetatable({}, {__mode = ‘v’})
task.spawn(function()
while true do
table.create(10^6)
print(Weak)
task.wait()
end
end)
return Weak
And in this first example, as you see the table never get’s gced.
I know this is specfically an issue with cyclic references, because if I reference an instance it still gets collected
local Weak = require(script.Parent.ModuleScript)
local Table = {
Event = require(game.ServerScriptService.Signal).new()
}
Table.Event:Connect(function()
print(workspace.Baseplate)
end)
Weak[2] = Table
This does get collected.
And the bizzare thing is, this only happens in the script corourtine, if I spawn a new coroutine it does getcollected
local Weak = require(script.Parent.ModuleScript)
task.spawn(function()
local Table = {
Event = require(game.ServerScriptService.Signal).new()
}
Table.Event:Connect(function()
print(Table)
end)
Weak[2] = Table
end)
Which doesn’t make sense to me, because in both cases “Table” it isn’t accessible anymore, once the script is done running or the coroutine finishes. But even more this specfically seems to be an issue with cyclic references