Measure Lua heap growth caused by running a snippet
measure-memoryMeasure Lua heap allocation of a snippet by comparing gcinfo() before and after execution to detect memory leaks or heavy allocations.
Instructions
Measure how much Lua heap memory a snippet allocates: read gcinfo() (the live Lua heap size in KB) immediately before running your code, run it once (compiled via loadstring, executed inside a pcall), then read gcinfo() again and report the delta. Use this to spot leaks or unexpectedly heavy allocations — e.g. confirm a function frees what it creates, see how big a table a constructor builds, or detect a snippet that balloons the heap. Caveats: gcinfo reports the WHOLE Lua heap, so concurrent game activity and garbage collection between the two samples add noise; a negative deltaKB means a GC cycle ran (it does NOT mean your code freed memory). For a cleaner reading, allocate enough to dwarf the noise or run a tight loop inside code. A compile error or a runtime error is reported in error with ok=false (the before/after samples are still returned). Requires gcinfo and loadstring (both guarded). Returns { beforeKB, afterKB, deltaKB, ok, error? } or { error }. Signature: { code: string, threadContext: number? }. Phase: act; cost=high; idempotency=contextual-write. Requires: active-client, explicit-mutation-approval, validated-source. Produces: structured-result. Verify with: assert-state. Safety: MUTATING; writes live game/client state. On failure: inspect tool-schema for exact fields, defaults, constraints, and an invocation example.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | The Luau snippet to measure. Compiled with loadstring and run once between two gcinfo() samples. Whatever it returns is ignored; only the change in heap size is reported. Allocate enough (or loop) so the delta stands out above background GC noise. | |
| threadContext | No | Optional Roblox thread identity for this call; omit it to use the server default. |