I was reading the WeakMap's description and it said:
In native WeakMaps, references to key objects are held "weakly", which means that they do not prevent garbage collection in case there would be no other reference to the object.
From reading this, my understanding is that WeakMaps are used in instances where you're trying to take advantage of JavaScript's garbage collection. What I don't understand fundamentally is the line I bolded.
Why, in a normal Map, would objects with no references to them not be garbage collected? What's the advantage to this, and do I have to explicitly delete from normal Maps?
"Why, in a normal Map, would objects with no references to them not be garbage collected?" because the map itself has a reference to the object. As long as there is a reference, the object is not gced. - Felix Kling
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With