3 ms·
I'm not aware of a way to control the GC behavior of an object in JS. The memory will be freed, and that's all. If something else needed to be done, I don't t
by recursive 3y ago
I'm not aware of a way to control the GC behavior of an object in JS. The memory will be freed, and that's all. If something else needed to be done, I don't think there's a way to do it. Happy to be proven wrong though.
- Drakim 3y agoYou 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.
- deleted 3y ago[deleted]