Memory safety monitor that wraps a RefRegistry.

Provides configurable thresholds, periodic leak checks, and pressure alerts. Designed for dev-mode diagnostics or production monitoring of SDK memory usage.

1.2.0

const guard = new MemoryGuard(registry, {
maxRefAgeMs: 30_000,
maxActiveRefs: 50,
checkIntervalMs: 10_000,
});

guard.onPressure(stats => {
console.warn('⚠️ Memory pressure:', stats.active, 'active refs');
});

guard.onLeak(report => {
console.error('🔴 Leaked ref:', report.tokenName, '#' + report.refId);
});

Implements

Constructors

Accessors

  • get underPressure(): boolean
  • Whether the active ref count exceeds the threshold.

    Returns boolean

Methods

  • Subscribe to memory pressure events.

    Fires when the active ref count exceeds maxActiveRefs during a periodic check.

    Parameters

    • handler: ((stats: RefStats) => void)
        • (stats): void
        • Parameters

          Returns void

    Returns void