Skip to content

typescript.unbounded_memory

Stability High

Detects data structures that can grow without bounds, leading to OOM.

Unbounded memory:

  • Causes OOM — Process crashes
  • Cascading failures — Other services impacted
  • Hard to diagnose — Gradual memory growth
// ❌ Before (unbounded array)
const events: Event[] = [];
socket.on('event', (event) => {
events.push(event); // Grows forever!
});
// ✅ After (with limit)
import { CircularBuffer } from 'circular-buffer';
const events = new CircularBuffer<Event>(1000);
socket.on('event', (event) => {
events.push(event); // Old events evicted
});
// Or with manual limit:
const MAX_EVENTS = 1000;
const events: Event[] = [];
socket.on('event', (event) => {
if (events.length >= MAX_EVENTS) {
events.shift();
}
events.push(event);
});
  • Arrays growing in event handlers
  • Maps/Sets accepting unbounded input
  • Queues without size limits

Unfault adds capacity limits and bounds checks.