1-- track collections
 2
 3local M = {}
 4
 5-- import list
 6local setmetatable, stderr, collectgarbage =
 7         setmetatable, io.stderr, collectgarbage
 8
 9_ENV = nil
10
11local active = false
12
13
14-- each time a table is collected, remark it for finalization on next
15-- cycle
16local mt = {}
17function mt.__gc (o)
18  stderr:write'.'    -- mark progress
19  if active then
20    setmetatable(o, mt)   -- remark object for finalization
21  end
22end
23
24
25function M.start ()
26  if not active then
27    active = true
28    setmetatable({}, mt)    -- create initial object
29  end
30end
31
32
33function M.stop ()
34  if active then
35    active = false
36    collectgarbage()   -- call finalizer for the last time
37  end
38end
39
40return M