Utility to track memory allocations.

This uses WeakRef internally to avoid holding a reference past its lifetime.

Example

// Enable the memory tracker (disabled by default).
MemoryTracker.enable = true;

const texture = new Texture();

MemoryTracker.track(texture, 'my tracked texture');

const allocated = MemoryTracker.getTrackedObjects();

// allocated should be { Texture: [{ name: 'my tracked texture', value: texture]}

Constructors

Accessors

Methods

  • Returns an array of all valid tracked objects (that have not been garbage collected).

    Important note: this array will hold actual references (dereferenced WeakRefs). They will no longer be removed by the garbage collector as long as values in this arrays exist ! You should make sure to empty this array when you are finished with it.

    Returns Record<string, {
        name: string;
        value: object;
    }[]>

    The tracked objects.

  • Registers an object to the memory tracker.

    Parameters

    • obj: object

      The object to track.

    • name: string

      The name of the tracked object. Does not have to be unique.

    Returns void