Created
September 21, 2023 07:19
-
-
Save outsinre/28cc38d50d6ee8a99e0058e448603326 to your computer and use it in GitHub Desktop.
table_shrinking.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- memory test | |
local size = 1000000 | |
local t = {} -- create a table | |
local function report(title) | |
collectgarbage() | |
collectgarbage() | |
print(title, collectgarbage("count")) | |
end | |
report("start") | |
for i = 1,size do -- fill the table with values, causing the c-size structure of the table to expand several times over | |
t[i] = {} | |
end | |
report("filled") | |
for i = 1,size do -- clear individual values from the table. But the table structures itself will not shrink back | |
t[i] = nil | |
end | |
report("emptied") -- replace the table structure, such that it get's GC'ed and it finally releases its memory | |
t = {} | |
report("cleared") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment