filtergc Filters objects in the garbage collector based on specified criteria.
filtergc ( type : "function" | "table" , options : table , returnOne ? : boolean ) -> any ? | { any }
Parameter Type Description typestringThe type of object to find ("function" or "table") optionstableFilter options returnOneboolean?Return the first match instead of an array (default: false)
Type Description any? or tableThe first match when returnOne is true; otherwise an array of matches
filtergc efficiently searches through garbage-collected objects with specific filter criteria. This is more performant than manually iterating through getgc().
Option Type Description NamestringMatch function name ConstantstableMatch constants in function UpvaluestableMatch upvalue values HashstringMatch the value returned by getfunctionhash IgnoreExecutorbooleanExclude Volt-created functions (default: true) EnvironmenttableMatch the function's global environment StartLinenumberMatch the function's starting source line SourcestringMatch the function's short source name UpvalueCountnumberMatch the exact upvalue count ConstantCountnumberMatch the exact constant count
Option Type Description KeystableMatch table keys ValuestableMatch table values KeyValuePairstableMatch key-value pairs MetatabletableMatch metatable
local functions = filtergc ( "function" , {
Name = "targetFunction" ,
IgnoreExecutor = false
})
for _ , func in ipairs ( functions ) do
print ( "Found:" , func )
end
local functions = filtergc ( "function" , {
Constants = { "SomeUniqueString" , "AnotherString" },
IgnoreExecutor = false
})
local tables = filtergc ( "table" , {
Keys = { "Health" , "MaxHealth" , "Damage" }
})
for _ , tbl in ipairs ( tables ) do
print ( "Found table with game stats" )
end
local function targetFunction ()
return "unique constant"
end
local match = filtergc ( "function" , {
Name = "targetFunction" ,
IgnoreExecutor = false
}, true )
print ( match == targetFunction ) -- true
Function filters narrow the result: every supplied criterion must match
Constants, Upvalues, and Hash do not apply to C closures
getgc - Get all GC objects