# HG changeset patch # User Matthew Wild # Date 1619196811 -3600 # Node ID 0584f8251f88811fe2d7e8b25f1ec6cbb6ee34b7 # Parent 04cfdac393cca274d78ff46d40aee7723907d696 tests: Add test for correct GC with circular references This tests for an issue fixed by a8caec6c5429, where a callback holding a reference to the parser object was never collected. This was due to use of luaL_ref() which forced a reference to the callbacks table even when the parser was otherwise not referenced. diff -r 04cfdac393cc -r 0584f8251f88 tests/test.lua --- a/tests/test.lua Fri Apr 23 17:50:29 2021 +0100 +++ b/tests/test.lua Fri Apr 23 17:53:31 2021 +0100 @@ -357,6 +357,18 @@ collectgarbage(); collectgarbage() assert(math.abs(gcinfo() - x) <= 2) +-- test for GC (circular references) +print("testing garbage collection (circular reference)") +collectgarbage(); collectgarbage() +local x = gcinfo() +for i=1,100000 do + -- due to a small bug in Lua... + if (math.mod or math.fmod)(i, 100) == 0 then collectgarbage() end + local p; + p = lxp.new({ StartElement = function () print(p) end }); +end +collectgarbage(); collectgarbage() +assert(math.abs(gcinfo() - x) <= 2) print"OK"