-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex23.4.lua
More file actions
20 lines (20 loc) · 888 Bytes
/
ex23.4.lua
File metadata and controls
20 lines (20 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
local count = 0
local mt = {__gc = function () count = count - 1 end}
local a = {}
for i = 1, 10000 do
count = count + 1
a[i] = setmetatable({}, mt)
end
collectgarbage()
print(collectgarbage("count") * 1024, count) -- nothing is collected, count is
-- 10000
a = nil
collectgarbage()
print(collectgarbage("count") * 1024, count) -- a's keys are collected, count is
-- still 0, but 10000 tables is not
-- collected yet, only finalizers
-- are executed 582436 bytes used
-- (2)
collectgarbage()
print(collectgarbage("count") * 1024, count) -- 10000 table has already been
-- collected, count is 0