diff --git a/files/en-us/web/javascript/reference/global_objects/weakmap/index.html b/files/en-us/web/javascript/reference/global_objects/weakmap/index.html index be3efb398230a80..be773277f3c3d91 100644 --- a/files/en-us/web/javascript/reference/global_objects/weakmap/index.html +++ b/files/en-us/web/javascript/reference/global_objects/weakmap/index.html @@ -29,9 +29,9 @@

Why WeakMap?

  • The second inconvenience is a memory leak because the arrays ensure that references to each key and each value are maintained indefinitely. These references prevent the keys from being garbage collected, even if there are no other references to the object. This would also prevent the corresponding values from being garbage collected.
  • -

    By contrast, native WeakMaps hold "weak" references to key objects, which means that they do not prevent garbage collection in case there would be no other reference to the key object. This also avoids preventing garbage collection of values in the map. Native WeakMaps can be particularly useful constructs when mapping keys to information about the key that is valuable only if the key has not been garbage collected.

    +

    By contrast, native WeakMaps hold "weak" references to key objects. As such native WeakMaps do not prevent garbage collection, which eventually removes references to the key object. "Weak" references also avoid preventing garbage collection of values in the map. WeakMaps can be particularly useful constructs when mapping keys to information about the key that is valuable only if the key has not been garbage collected.

    -

    Because the references are weak, WeakMap keys are not enumerable. There is no method to obtain a list of the keys. If they were, the list would depend on the state of garbage collection, introducing non-determinism. If you want to have a list of keys, you should use a {{jsxref("Map")}}.

    +

    Because the references are weak, WeakMap keys are not enumerable. There is no method to obtain a list of the keys. If there was, the list would depend on the state of garbage collection, introducing non-determinism. If you want to have a list of keys, you should use a {{jsxref("Map")}}.

    Constructor