Docs / Garbage collector

Garbage collector

Walk the Luau heap.

Library#12 of 23 Functions2
getgc(includeTables: boolean?) → {any}
Every live collectable value on the heap. Passing true includes tables.
lua
for _, obj in ipairs(getgc(true)) do
    if typeof(obj) == "table" and rawget(obj, "myFlag") then
        print("found:", obj)
    end
end
filtergc(kind: "function" | "table", filter: table, findFirst: boolean?) → any | {any}
Filter GC objects by predicate. For functions: {Name, IgnoreExecutor, Constants, Upvalues, Hash}. For tables: {Keys, Values, KeyValuePairs, Metatable}. findFirst=true returns the first match instead of a list.
lua
local secret = filtergc("table", {
    Keys = {"password", "token"},
}, true)
print(secret)