Leak Detection
Automatic detection and cleanup of memory leaks.
1 min readEdit this page
What is detected
| Type | Auto Fix |
|---|---|
| Event listener accumulation | Warns |
| Cache overflow | Prunes |
| Timer accumulation | Warns |
| Global pollution | Warns |
| Unused module cache | Clears |
| High heap usage | Triggers GC |
Track resources
import { trackTimer, trackCache } from '@restjs/memory'
const timer = trackTimer(setTimeout(work, 5000))
const cache = trackCache('sessions', new Map(), 10000)Per-request
import { memoryMiddleware } from '@restjs/memory'
app.use(memoryMiddleware({ leakThresholdMb: 50, exposeHeader: true }))