$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #191

Which fix removes the bug?

const cache = new Map();
function remember(node, value) {
  cache.set(node, value);
}
  1. Use a WeakMap or evict
  2. Clear it on each call
  3. Store values as JSON
  4. Key the map by index
A strong Map key keeps detached nodes alive forever, so the cache is a memory leak.
Play Problem Solving ▸