Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve clarity and grammar #3009

Merged
merged 1 commit into from
Mar 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ <h3 id="Why_WeakMap">Why <em>Weak</em>Map?</h3>
<li>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.</li>
</ol>

<p>By contrast, native <code>WeakMap</code>s 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.</p>
<p>By contrast, native <code>WeakMap</code>s hold "weak" references to key objects. As such native <code>WeakMap</code>s 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. <code>WeakMap</code>s can be particularly useful constructs when mapping keys to information about the key that is valuable <em>only if</em> the key has not been garbage collected.</p>

<p><strong>Because the references are weak, <code>WeakMap</code> keys are not enumerable.</strong> 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")}}.</p>
<p><strong>Because the references are weak, <code>WeakMap</code> keys are not enumerable.</strong> 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")}}.</p>

<h2 id="Constructor">Constructor</h2>

Expand Down