我发现我在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
任何帮助解决我的内存泄漏问题将不胜感激。
再次感谢
杰夫