WeakMap is one of JavaScript's most underappreciated data structures. It enables memory-safe patterns that are impossible with regular Maps.
Quick Recap: WeakMap vs Map
WeakMap keys are weakly held — when there are no other references to the key object, both the key and value are garbage collected. This means no memory leaks.
Use Case 1: Private Instance Data
Use Case 2: Memoization with Object Keys
Use Case 3: DOM Element Metadata
Use Case 4: Preventing Circular Reference Leaks
Use Case 5: Framework Internals
React, Vue, and other frameworks use WeakMaps internally to associate component instances with their fiber/vnode without preventing garbage collection. This is why unmounted components don't leak memory.