Consider the following example:
function Process() local Container=NewContainer() Container:On(EventType.Add,function() Container:DoSomething() end) -- Does not Garbage Collect end
In luabridge, I save function() as a LuaRef , which extends the lifetime of the Container , and it will not be GCed because it is RefCountedObjectPtr
Here is a workaround that I use to use a weak table that works but looks ugly:
function Process() local Container=NewContainer() local ParamsTable={ Container=Container } setmetatable(ParamsTable, { __mode = 'k' }) Container:On(EventType.Add,function() ParamsTable.Container:DoSomething() end) -- Garbage Collects fine end
Is there a way to have a LuaRef function that works similarly to this? Or maybe there is another workaround?
Grapes
source share