Web Vitals & Performance (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
Preventing Memory Bloat in Single Page Applications (SPAs).
senior LevelSystem Design
In Simple Words: In apps running for hours without full-page reloads:
- Always unsubscribe from RxJS observables or remove DOM event listeners in unmount lifecycle hooks.
- Avoid accumulating data indefinitely in client-side caches (e.g. Apollo Client, TanStack Query); enforce maximum cache age and garbage collection limits.
- Use WeakMap / WeakSet for caching DOM element references so elements can be garbage collected when removed from the DOM.