The DOM thing is one example use case. Another would be adding metadata to request/response objects in Node.js apps so that it can be read by middlewares later in the stack (without needing to modify any TypeScript interfaces).
Yes, there's a delete method for weak maps and weak sets. Like adding, it has zero effect on GC, which can't be manually controlled in JavaScript. Note that the delete operator used on an object also doesn't guarantee immediate GC.
The DOM thing is one example use case. Another would be adding metadata to request/response objects in Node.js apps so that it can be read by middlewares later in the stack (without needing to modify any TypeScript interfaces).
Yes, there's a
deletemethod for weak maps and weak sets. Like adding, it has zero effect on GC, which can't be manually controlled in JavaScript. Note that thedeleteoperator used on an object also doesn't guarantee immediate GC.I meant to say "eligible for gc".