Managing Resource Usage
Long-running scripts have to clean up after themselves, or they slowly eat memory until the game stutters or crashes. Managing resources — instances, connections and tables — is what keeps a script healthy over a whole session.
Get a free executor
You need an executor to run any Roblox script. Grab one free.
Memory leaks in Roblox
A leak is memory that is allocated and never freed. In Roblox the classic causes are instances that are created but never destroyed, event connections that are never disconnected, and tables that grow forever. Memory that only ever climbs is the tell.
The fix is discipline about cleanup, not clever tricks.
Clean up instances and connections
When you are done with something you created, get rid of it:
- Call :Destroy() on instances you no longer need.
- Keep the connection from :Connect() and call :Disconnect() when it is no longer required.
- Clear references (set to nil) so the garbage collector can reclaim them.
- Remove entries from tables that grow over time.
Reuse instead of recreate
Constantly creating and destroying objects (bullets, UI elements, effects) churns memory and CPU. Where you can, reuse a pool of objects — hide and reposition them instead of destroying and remaking. It is steadier and faster.
This is the resource side of optimizing script efficiency.
Watch it over time
Use the memory stats and understanding performance metrics to confirm usage is stable across a long session, not slowly creeping up. A leak that is invisible in a 2-minute test shows up clearly over 20.