lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


There seems to be a stupid bug in the collection of weak tables in Lua
5.0.2. Once a weak table survives a garbage collection, it is never
collected. A simple example is like this:

  a = {}
  print(gcinfo())
  for i = 1, 10000 do
    a[i] = setmetatable({}, {__mode = "v"})
  end
  collectgarbage()
  a = nil
  collectgarbage()
  print(gcinfo())     -- should be near the first value...


The patch is a single line in lgc.c:

@@ -366,7 +366,7 @@
   GCObject *curr;
   int count = 0;  /* number of collected items */
   while ((curr = *p) != NULL) {
-    if (curr->gch.marked > limit) {
+    if ((curr->gch.marked & ~(KEYWEAK | VALUEWEAK)) > limit) {
       unmark(curr);
       p = &curr->gch.next;
     }

(Bug reported by Chromix.)

As far as we checked, this bug is not present in Lua 5.1 beta.

-- Roberto