3 ms·
In C#, the garbage collector will eventually call the destructor that will dispose the object. It just won't happen deterministically with the code. I assume
by wvenable 3y ago
In C#, the garbage collector will eventually call the destructor that will dispose the object. It just won't happen deterministically with the code.
I assume there would be similar logic for JavaScript but I haven't looked at the specification.
It is not always a mistake to miss the using keyword -- if you're taking ownership of the object, then you will dispose of it manually (potentially in your own dispose method).
- recursive 3y agoI'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]