public virtual void Dispose(bool dispose) { #if THREAD_SAFT || HOTFIX_ENABLE lock (luaEnvLock) { #endif if (disposed) { return; } Tick(); LuaAPI.lua_close(L); ObjectTranslatorPool.Instance.Remove(L); if (translator != null) { translator = null; } L = IntPtr.Zero; disposed = true; #if THREAD_SAFT || HOTFIX_ENABLE } #endif }
public virtual void Dispose(bool dispose) { #if THREAD_SAFE || HOTFIX_ENABLE lock (luaEnvLock) { #endif if (disposed) { return; } Tick(); if (!translator.AllDelegateBridgeReleased()) { throw new InvalidOperationException("try to dispose a LuaEnv with C# callback!"); } LuaAPI.lua_close(L); ObjectTranslatorPool.Instance.Remove(L); translator = null; rawL = IntPtr.Zero; disposed = true; #if THREAD_SAFE || HOTFIX_ENABLE } #endif }
public virtual void Dispose(bool dispose) { #if THREAD_SAFE || HOTFIX_ENABLE lock (luaEnvLock) { #endif if (disposed) { return; } Tick(); if (!translator.AllDelegateBridgeReleased()) { #if UNITY_EDITOR var delegates = translator.GetAllDelegateBridges(); foreach (var kv in delegates) { if (kv.Value.IsAlive) { int key = kv.Key; } } #endif throw new InvalidOperationException("try to dispose a LuaEnv with C# callback!"); } ObjectTranslatorPool.Instance.Remove(L); LuaAPI.lua_close(L); translator = null; rawL = IntPtr.Zero; disposed = true; #if THREAD_SAFE || HOTFIX_ENABLE } #endif }
public virtual void Dispose(bool dispose) { #if THREAD_SAFT || HOTFIX_ENABLE lock (luaEnvLock) { #endif if (disposed) { return; } Tick(); if (!translator.AllDelegateBridgeReleased()) { // FIX 如果外部没有正确清理lua注册的委托,这里会抛异常,导致lua无法正常销毁 // 而由于lua使用的不是托管内存,所以在Editor下会有内存泄漏,这里改为不抛异常,强制清理所有委托的引用。 // throw new InvalidOperationException("try to dispose a LuaEnv with C# callback!"); translator.ForceDisposeAllDelegateBrige(); GameDebug.LogError("try to dispose a LuaEnv with C# callback!"); } LuaAPI.lua_close(L); ObjectTranslatorPool.Instance.Remove(L); if (translator != null) { translator = null; } rawL = IntPtr.Zero; disposed = true; #if THREAD_SAFT || HOTFIX_ENABLE } #endif }