INNER CODE UNIT · JavaScript
startWatchdog
furey/mongodb-lens · mongodb-lens.js:192
const startWatchdog = () => {
if (watchdog) clearInterval(watchdog)
watchdog = setInterval(() => {
const memoryUsage = process.memoryUsage()
const heapUsedMB = Math.round(memoryUsage.heapUsed / 1024 / 1024)
const heapTotalMB = Math.round(memoryUsage.heapTotal / 1024 / 1024)
if (heapUsedMB > config.memory.warningThresholdMB) {
log(`High memory usage: ${heapUsedMB}MB used of ${heapTotalMB}MB heap`, true)
if (heapUsedMB > config.memory.criticalThresholdMB) {
log('Critical memory pressure. Clearing caches…', true)
clearMemoryCache()
if (config.memory.enableGC && global.gc) {
global.gc()
} else if (config.memory.enableGC) {
log('Garbage collection requested but not available. Run Node.js with --expose-gc flag.', true)