我發現我在C#/ Lua LuaInterface項目中有一個錯誤的內存泄漏。我已經在C#中寫了一個簡單的測試函數,每隔0.5秒從Lua中調用一次。我可以看到每個循環都會增加Lua內存使用量。我最新的C#端代碼LuaInterface內存泄漏問題
public LuaTable testMemTable()
{
LuaTable tabx = m_lua.GetTable("tabx");
if (tabx != null)
{
tabx.Dispose();
tabx = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}
m_lua.NewTable("tabx");
tabx = m_lua.GetTable("tabx");
for (int i = 0; i < 20000; i++)
tabx[i] = i * 10;
return tabx;
}
儘管做tabx.Dispose()和TABX = NULL,然後迫使GC我仍然看到該內存不被釋放。沒有LuaInterface函數來釋放以前分配的表,所以我爲了釋放內存我還能做些什麼?
的Lua中端代碼非常簡單
while true do
myAPILibs.testMemTable()
if tabx ~= nil then
print(string.format("Size = %d", #tabx))
else
print(string.format("Size = nil"))
end
print(tabx, tabx[111])
myAPILibs.sleep(500)
print("Before ", collectgarbage("count") * 1024)
collectgarbage("collect")
print("After ", collectgarbage("count") * 1024)
end
任何幫助解決我的內存泄漏問題將不勝感激。
再次感謝
傑夫