Class: RenderableGCSystem

RenderableGCSystem

The RenderableGCSystem is responsible for cleaning up GPU resources that are no longer being used.

When rendering objects like sprites, text, etc - GPU resources are created and managed by the renderer. If these objects are no longer needed but not properly destroyed (via sprite.destroy()), their GPU resources would normally leak. This system prevents that by automatically cleaning up unused GPU resources.

Key features:

  • Runs every 30 seconds by default to check for unused resources
  • Cleans up resources not rendered for over 1 minute
  • Works independently of rendering - will clean up even when not actively rendering
  • When cleaned up resources are needed again, new GPU objects are quickly assigned from a pool
  • Can be disabled with renderableGCActive:false for manual control

Best practices:

  • Always call destroy() explicitly when done with renderables (e.g. sprite.destroy())
  • This system is a safety net, not a replacement for proper cleanup
  • Adjust frequency and timeouts via options if needed

Example:

// Sprite created but reference lost without destroy
let sprite = new Sprite(texture);

// internally the renderer will assign a resource to the sprite
renderer.render(sprite);

sprite = null; // Reference lost but GPU resources still exist

// After 1 minute of not being rendered:
// - RenderableGC will clean up the sprite's GPU resources
// - JS garbage collector can then clean up the sprite itself

new RenderableGCSystem (renderer)

Creates a new RenderableGCSystem instance.

Name Type Description
renderer Renderer

The renderer this garbage collection system works for

Implements

  • {System.<RenderableGCSystemOptions>}

Members

defaultOptions RenderableGCSystemOptions static

Default configuration options for the garbage collection system. These can be overridden when initializing the renderer.

Properties:
Name Type Default Description
renderableGCActive boolean true

Enable/disable the garbage collector

renderableGCFrequency number 30000

How often to run garbage collection in ms (default 30 seconds)

renderableGCMaxUnusedTime number 60000

Time in ms before an unused resource is collected (default 1 minute)

enabled boolean

Gets whether the garbage collection system is currently enabled.

enabled

Enables or disables the garbage collection system. When enabled, schedules periodic cleanup of resources. When disabled, cancels all scheduled cleanups.

maxUnusedTime number

Maximum time in ms a resource can be unused before being garbage collected

Methods

addManagedArray (context, hash) void

Adds an array to be managed by the garbage collector.

Name Type Description
context T

The object containing the array

hash string

The property name of the array

addManagedHash (context, hash) void

Adds a hash table to be managed by the garbage collector.

Name Type Description
context T

The object containing the hash table

hash string

The property name of the hash table

addRenderable (renderable) void

Starts tracking a renderable for garbage collection.

Name Type Description
renderable Renderable

The renderable to track

destroy () void

Cleans up the garbage collection system. Disables GC and removes all tracked resources.

init (options) void

Initializes the garbage collection system with the provided options.

Name Type Description
options RenderableGCSystemOptions

Configuration options for the renderer

prerender (options) void

Updates the GC timestamp and tracking before rendering.

Name Type Description
options RenderOptions

The render options

options.container

The container to render

run () void

Performs garbage collection by cleaning up unused renderables. Removes renderables that haven't been used for longer than maxUnusedTime.