What happens to the entries in a WeakMap when there are no other references to the key?

  • They are automatically removed from the WeakMap
  • They are retained in the WeakMap
  • They trigger an error
  • They are marked for deferred removal
In a WeakMap, entries are automatically removed when there are no other references to the key. This behavior makes WeakMap suitable for scenarios where memory management is crucial, and entries should be tied to the existence of their key elsewhere in the program.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *