Find and fix memory leaks in Node.js or browser applications
Diagnose and fix a memory leak:
Environment: {{ENVIRONMENT}}
Symptoms: {{SYMPTOMS}}
Investigation approach:
1. Take heap snapshots before and after suspected leak
2. Compare snapshots to find growing objects
3. Check for common patterns:
- Event listeners not removed
- Closures holding references
- Global variables accumulating data
- Timer intervals not cleared
- Unclosed database connections
- Cache without eviction
4. Identify the root cause
5. Implement fix
6. Verify fix with heap snapshot comparison
Provide:
- Memory profiling instructions
- Code changes to fix the leak
- Test to verify fix
- Prevention patterns for future codeFixing memory leaks in applications