tests/test.lua

changeset 28
0584f8251f88
parent 11
b2a77ebe7aed
child 29
3f77d77806c1
--- 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"
 

mercurial