Returns a new array of the live, collectable objects the garbage collector is tracking in the current Lua state. By default only functions are returned; pass true to also include tables, userdata, and threads.

Parameters

boolean
default:"false"
When true, the result also contains tables, userdata, and threads. When false or omitted, only functions are returned.

Returns

table
A fresh array (1-indexed) of the matching objects. The array itself is not included in its own result.

Behavior

The walk is a point-in-time snapshot of one VM:
  • Only live objects are included. Objects already marked dead by the collector are skipped.
  • The result is scoped to the Lua state you call from. Objects belonging to other Actor VMs are not visible here. Use the actors library to reach those states.
  • Proto objects and other internal-only collectables are never returned; the set is limited to functions and, with includeTables, tables, userdata, and threads.
If you are searching for one specific function or table, reach for filtergc instead. Walking the full getgc result in Luau allocates a large array and then throws most of it away, whereas filtergc matches during the walk and keeps only what you asked for.

Example

Pull in every collectable category and tally what’s live by type:

Errors