Skip to content

bug: TTLCache Intervals are not terminating and are not being cleared by the garbage collector. #522

@Kolosok86

Description

@Kolosok86

steam

this._jobs = new StdLib.DataStructures.TTLCache(1000 * 60 * 2); // job callbacks are cleaned up after 2 minutes
this._jobsGC = new StdLib.DataStructures.TTLCache(1000 * 60 * 2);
this._richPresenceLocalization = {};
this._incomingMessageQueue = [];
this._useMessageQueue = false; // we only use the message queue while we're processing a multi message
this._ttlCache = new StdLib.DataStructures.TTLCache(1000 * 60 * 5); // default 5 minutes

TTLCache stdlib

/**

  • Construct a new TTLCache.

  • @param {int} ttlMilliseconds - Default time to live in milliseconds for each entry

  • @param {int} [gcIntervalMilliseconds=300000] - Time between garbage collections (default 1 minute)

  • @constructor
    */
    constructor(ttlMilliseconds: number, gcIntervalMilliseconds: number = 60000) {
    this.#container = new Map<string, {value: T, expire: number}>();
    this.#ttl = ttlMilliseconds;

    // Force a GC every minute
    setInterval(() => this.#gc(), gcIntervalMilliseconds).unref();
    }

Screenshots and Error Logs

When the class is finalized and removed from memory, some intervals remain active and are not properly cleared.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions