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);}); Copy
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);});
Number of currently active refs.
Current ref statistics from the underlying registry.
Whether the active ref count exceeds the threshold.
Check for potential leaks (refs older than maxRefAgeMs).
maxRefAgeMs
Dispose the guard — stops the timer, clears handlers.
Subscribe to GC-detected leak events.
Delegates to the underlying RefRegistry.onLeak.
Subscribe to memory pressure events.
Fires when the active ref count exceeds maxActiveRefs during a periodic check.
maxActiveRefs
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.
Since
1.2.0
Example