Garbage collection on Map and WeakMap collections in es6

I read the description of WeakMap and he said:

In native WeakMaps, references to key objects are stored "weakly", which means that they do not prevent garbage collection if there is no reference to the object .

From this I understand that WeakMaps are used when you are trying to use JavaScript garbage collection. What I don’t understand fundamentally is the line that I highlighted.

Why on a regular map objects that do not have links to them will not be collected by garbage? What is the advantage for this and should I explicitly remove from regular Maps?

+5
source share
2 answers

"Why, on a regular map, objects that do not have links to them will not collect garbage?" because the map itself has a link to the object. As long as there is a link, the object is not hidden. - Felix Kling

0
source

in normal Map , Map is a reference to an object

0
source

Source: https://habr.com/ru/post/1237964/


All Articles