lua-users home
lua-l archive

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


Mike Pall wrote:
If you're storing all your userdatas in the array part, a simple
't.foo = nil' triggers the shrinking. If you'r storing them in
the hash part, a 't[1] = nil' will do.

My userdatas are keys in a weak keyed table. I've just tried your recipe in my application, both with t.foo=nil and with t[1]=nil -- it didn't help.

Here's  a modified version of your example:
  collectgarbage()
  local t={}
  print(gcinfo())
  for i=1,1e6,3 do t[i]=true end
  for i=1,1e6,3 do t[i]=nil end
  collectgarbage()
  print(gcinfo())
  t.foo, t[1], t[2] = nil
  print(gcinfo())

Output:
20
16404
16404

--
Shmuel