SpinTheMic
Pro

Interview practice question

Caching results keyed by objects without leaking memory

Frontend Engineering · JavaScript Core · Experienced

You want to cache computed results for objects passed into a function, but a Map cache causes memory leaks. What do you do?

What a strong answer covers

Your AI report card counts how many of these ideas you cover.

  • Map keeps keys alive.
  • WeakMap allows GC of keys.
  • Not iterable or sized.
  • Works only for object keys.
  • Combine with immutability for correctness.
Practise this topic

Start without signing up. Sign in free to get an AI report card on your answer.

See all topics