ugui tolua
local test = {}
test.b = gameobject
test.c = gameobject:GetComponent(typeof(UnityEngine.UI.Button ))
First call UnityEngine.GameObject.Destroy(test.b)
If the test table is also recycled by ToLuaUnRef, it is found that
test.c references the Button object in c#. Released from ObjectTranslator.objectsBackMap
The object in ObjectTranslator is not released, it should be you still refer to this object in Lua. The normal practice is to ensure that the references in Lua are released in time, but there will be a lot of code with xxx=nil. If the project does not pay attention to these at the beginning, it will be very annoying to change it later. Our approach is to traverse in BasePanel
function BasePanel:cleanVar() for k,v in pairs(self) do if (type(v) == "userdata" or type(v) == "table") and k ~= "gameObject" then self[k] = nil end endend
To close the UI interface is to call cleanVar() in OnDestroy()
function BasePanel:cleanVar() for k,v in pairs(self) do if (type(v) == "userdata" or type(v) == "table") and k ~= "gameObject" then self[k] = nil end endend