Skip to main content

WeakSet

A WeakSet-typed variable holds the JS WeakSet collection — like a Set, but every member must be an object (or array), never a primitive like a string or a number. The default-value text you type into the Variables panel must be a JSON array whose elements are all objects/arrays, e.g. [{"id":1}]; typing a plain-value array like ["a","b"] is rejected with a clear message, since a real JS WeakSet throws at runtime if you try to add a string or number to it.

Compiles to

let trackedObjects = new WeakSet([{ id: 1 }]);

Leaving the default-value field empty still compiles to a real, constructed WeakSet — new WeakSet() — rather than leaving the variable undeclared.

Get Variable / Set Variable

A Get trackedObjects node reads it back; a Set trackedObjects node assigns a new value and continues:

Get Variable

Set Variable

The Set node's "Value" pin takes the same object-only JSON-array text as the default-value field — an unwired literal there is wrapped in new WeakSet(...) the exact same way, and is subject to the same objects-only validation.

Use case

  • Tracking objects for cleanup: Keep track of a set of request objects, sessions, or other objects you want to associate some state with, without preventing them from being garbage-collected once nothing else references them — unlike a regular Set, a WeakSet doesn't keep its members alive on its own.