ReferenceEnvironment

getgc

Returns the collectable values that currently exist in the game's Luau state.

Syntax

getgc(includeTables: boolean?) -> {any}

Also available as

get_gc

Parameters

ParameterTypeDescription
includeTablesboolean?When true, include tables, userdata and threads as well as functions. Defaults to false.

Returns

TypeDescription
{any}An array of the values the garbage collector currently tracks.

Description

By default the list holds only functions, which keeps it small and fast. Pass true to also get tables, userdata and threads. The result is a snapshot of this VM, not all Actor VMs. Unreachable values can remain until collected; a later allocation or collection can change the result.

For a targeted search, filtergc is faster and simpler than looping over this list yourself.

Example

for _, value in getgc() do
    if type(value) == "function" and islclosure(value) and debug.info(value, "n") == "CalculateDamage" then
        print("found", value)
    end
end

Notes

These are Game executor contracts. Check build requirements and session lifetimes before using them.