RbxStu V3 Docs
  • Welcome
  • Information
    • Engine Information
      • Luau API Security
  • Stunc
    • Overview
    • Connections
    • Filesystem
      • readfile
      • writefile
      • appendfile
      • isfile
      • isfolder
      • listfiles
      • makefolder
      • delfile
      • delfolder
      • loadfile
      • dofile
  • Memory
    • getgc
    • reference_object
    • unreference_object
    • get_gc_threshold
  • Closures
    • isunhookable
    • makeunhookable
    • ishooked
    • restorefunction
    • hookfunction
    • hookmetamethod
    • isourclosure
    • iscclosure
    • islclosure
    • clonefunction
    • newcclosure
    • newlclosure
    • loadstring
Powered by GitBook
On this page
  1. Memory

get_gc_threshold

Overview of the get_gc_threshold function.

Function Characteristics

This function is pure; it does not modify any data when called.

Function definition
function get_gc_threshold(iWantADamnDouble: boolean?): string

Remarks

This function returns a string due to the GC threshold being irrepresentable as integers (Luau is limited to 32-bit integers, while the GC threshold is a 64-bit integer). Because of it, a string representation of the GCthreshold is returned by default; however, by providing the iWantADamnDouble value as true, you will obtain it as a Luau double-precision floating point number. The latter is not the default. due to accuracy concerns.

The GC threshold, after collection, increases by the following math equation:

// trigger cannot be correctly adjusted after a forced full GC.
// we will try to place it so that we can reach the goal based on
// the rate at which we run the GC relative to allocation rate
// and on amount of bytes we need to traverse in propagation stage.
// goal and stepmul are defined in percents
g->GCthreshold = g->totalbytes * (g->gcgoal * g->gcstepmul / 100 - 100) / g->gcstepmul;

In short, if the GC threshold is modified, it means that the Luau Garbage Collector collected some memory.

In the future, RbxStu V3 may allow access to more GC parameters; however, as of now it is not planned.

High-Level Overview

get_gc_thresholdwill return you the threshold before the Luau Garbage Collector runs again, useful for debugging memory usage. The return is a string by default; a number can be requested by passing in the optional iWantADamnDouble parameter as true.

Low-Level Overview

We validate the iWantADambDoubleargument, after which we push into the luau stack the L->global->GCthresholdfield, after which it is returned to the caller.

Previousunreference_objectNextClosures

Last updated 4 months ago