What is memory management in JS?
Allocation/deallocation of memory resources. Automated in JS.
What is garbage collection (GC)?
Automatic reclaiming of unused memory.
Explain mark-and-sweep GC.
Marks reachable objects, reclaims unmarked memory. Handles circular refs.
Common sources of memory leaks?
Globals, forgotten timers, closures, detached DOM, circular refs.
Prevent leaks from timers/listeners?
Clear timers, remove event listeners when done.
What is memory profiling?
Use dev tools to analyze memory usage and leaks.
What are WeakMap and WeakSet?
Collections with weak references, allowing GC of unused objects.
How does requestAnimationFrame help memory?
Schedules animations efficiently, reduces repaints and memory use.