Interface to the Lua garbage collector

See also Lua library functions.


collectgarbage(option [, arg])


  • option - One of the following options

    • collect - Performs a full garbage collection cycle
    • count - Returns the total Lua memory usage (in kilobytes)
    • restart - Restarts the garbage collector
    • setpause - Sets the garbage collector's pause percentage to arg; e.g., if 200, the collector waits for memory usage to double before starting a new cycle
    • setstepmul - Sets the garbage collector's speed (as a percentage relative to memory allocation) to arg; e.g., if 200, the collector runs twice as fast as memory is allocated
    • step - Performs a garbage collection step, with size arg
    • stop - Stops the garbage collector

  • arg - Argument applicable to some options

This function is defined in the Lua standard libraries