MemoryPressureHandler class

Handles memory pressure by clearing caches.

Usage:

// Register caches to be cleared under pressure
MemoryPressureHandler.registerCache('fileMetrics', FileMetricsCache.clearCache);

// Check periodically (e.g., every 100 files)
MemoryPressureHandler.checkAndRelieve();

// Or set up automatic threshold-based clearing
MemoryPressureHandler.enableAutoRelief(thresholdMb: 500);

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

isOverHardLimit bool
Whether the process RSS is currently over the hard cap, meaning rule execution should pause. Self-samples the real RSS on a throttle so callers can invoke it on the hot per-node path without a syscall every time.
no setter

Static Methods

checkAndRelieve() bool
Check memory pressure and relieve if needed.
clearAll() → void
Force clear all registered caches.
disableAutoRelief() → void
Disable automatic memory relief.
enableAutoRelief({int thresholdMb = 512, int checkIntervalFiles = 50}) → void
Enable automatic memory relief.
getStats() Map<String, dynamic>
Get statistics.
recordFileProcessed() → void
Record that a file was processed (for auto-relief timing).
registerCache(String name, void clearFunction(), {int priority = 50}) → void
Register a cache to be cleared under memory pressure.
relieve({bool clearAll = false}) → void
Clear caches to relieve memory pressure.
setHardRssLimitMb(int mb) → void
Set the hard RSS cap (MB). 0 or negative disables the valve.
unregisterCache(String name) → void
Unregister a cache.