getgc
Returns reachable GC objects. Pass true to include tables.
Syntax
getgc(includeTables?: any) -> table
Parameters
| Parameter | Type | Description |
|---|---|---|
includeTables? | any | The include tables value used by the call. |
Returns
| Type | Description |
|---|---|
table | An array of reachable GC objects, optionally including tables. |
Description
getgc walks the reachable objects in the game's Luau state and returns a snapshot table of functions, threads, userdata and optionally tables.
Pass true to include tables. The returned table is an array; iterate it with ipairs and filter by type for the objects you need.
Example
for _, object in ipairs(getgc(true)) do
if type(object) == "table" then
print(object)
break
end
end
Notes
- Mutating a returned environment affects every script that shares it.
- The heap changes constantly; a single call is only a snapshot.
- Scanning the full heap can return a large number of objects.