Fri, 23 Apr 2021 17:53:31 +0100
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.
tests/test.lua | file | annotate | diff | comparison | revisions |
--- 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"