Why in WeakMap key and value are not removed when you display the entire collection, but are removed when you display one element?
Example with "nulling" value. Why does the element still exist in the WeakMap collection in this case?
let weakMap = new WeakMap();
let obj = {name: 'Ivan'};
//adding some new element
weakMap.set({}, obj);
obj = null;
console.log(weakMap);
console.log(weakMap.get({}));
Whole collection
Example with "nulling" key:
What's going on here? What does it come from? The garbage collector does not have time to clean up everything or what?
Via Active questions tagged javascript - Stack Overflow https://ift.tt/6yA2kCB
Comments
Post a Comment