4 ms·
You can kinda use a WeakMap to later detect if an object has been dereferenced, and thus run some sorta cleanup routine.
by Drakim 3y ago
You can kinda use a WeakMap to later detect if an object has been dereferenced, and thus run some sorta cleanup routine.
- recursive 3y agoHow? WeakMap (and WeakSet, more directly) can detect if an object has been collected only if you have a reference to pass to it. If you have reference to the object in a variable or data structure, it won't have been eligible for collection in the first place.