Volt

getgc

Returns a table of all objects tracked by the garbage collector.

Syntax

getgc(includeTables?: boolean) -> table

Parameters

ParameterTypeDescription
includeTablesboolean?Whether to include tables (default: false)

Returns

TypeDescription
tableArray of all GC-tracked objects

Description

getgc returns all objects currently tracked by Luau's garbage collector. This is useful for finding specific functions, tables, or other objects in memory.

Example

-- Get all functions in memory
for _, obj in ipairs(getgc()) do
    if type(obj) == "function" then
        print("Found function:", obj)
    end
end

Finding Specific Functions

-- Find a function by its constants
local function findFunction(targetString)
    for _, obj in ipairs(getgc()) do
        if type(obj) == "function" then
            local constants = debug.getconstants(obj)
            for _, const in ipairs(constants) do
                if const == targetString then
                    return obj
                end
            end
        end
    end
    return nil
end

local targetFunc = findFunction("SomeUniqueString")

Including Tables

-- Get all tables (slower, more results)
local allObjects = getgc(true)

for _, obj in ipairs(allObjects) do
    if type(obj) == "table" and obj.SpecialKey then
        print("Found target table!")
    end
end

Notes

  • Without includeTables, only functions and other non-table objects are returned
  • Including tables can be slow due to the large number of tables in memory
  • Consider using filtergc for more targeted searches
  • filtergc - Filter objects with conditions

On this page