public void LuaCollectsObjectsAfterReferencesAreDisposed() { // In this test we repeatedly create and destroy table references to make sure the Lua GC is able to collect // them. We create a multiple of 1,000 tables since the runtime rewrites the reference table every 1,000 // reference destructions. This should return the runtime to exactly the same state as it was at the // beginning of the test. using (var runtime = new MemoryConstrainedLuaRuntime()) { using (var collect = (LuaFunction)runtime.Globals["collectgarbage"]) { collect.Call().Dispose(); var begin = runtime.MemoryUse; // Stress the GC a bit by creating and disposing tables, in batches of 100. for (int i = 0; i < 1000; ++i) { foreach (var t in Enumerable.Range(1, 100).Select(j => runtime.CreateTable()).ToList()) { t.Dispose(); } } // Now create a whole bunch of tables all at once. foreach (var t in Enumerable.Range(1, 10000).Select(j => runtime.CreateTable()).ToList()) { t.Dispose(); } collect.Call().Dispose(); Assert.AreEqual(begin, runtime.MemoryUse); } } }
public void NoMemoryErrorWhileInClr() { if (LuaRuntime.LUAJIT && IntPtr.Size == 8) { Assert.Ignore(); } using (var runtime = new MemoryConstrainedLuaRuntime()) { Action fn = () => { runtime.MaxMemoryUse = runtime.MemoryUse + 1; using (var x = runtime.CreateTable()) { x[1] = "This is a string that is way more than one byte long."; } runtime.MaxMemoryUse = long.MaxValue; }; using (var callback = runtime.CreateFunctionFromDelegate(fn)) { runtime.Globals["callback"] = callback; } runtime.DoString("callback()").Dispose(); } }
public void NoMemoryErrorWhileInClr() { using (var runtime = new MemoryConstrainedLuaRuntime()) { Action fn = () => { runtime.MaxMemoryUse = runtime.MemoryUse + 1; using (var x = runtime.CreateTable()) { x[1] = "This is a string that is way more than one byte long."; } runtime.MaxMemoryUse = long.MaxValue; }; using (var callback = runtime.CreateFunctionFromDelegate(fn)) { runtime.Globals["callback"] = callback; } runtime.DoString("callback()").Dispose(); } }
public LuaTable CreateTable() { return(runtime.CreateTable()); }