!7 set flag OshiNotSticky. cm whatever { transient SimpleLiveValue lvStatus = stringLiveValue(); switchable int max = 1024; switchable double interval = 10.0; visual jCenteredLiveValueLabel(lvStatus); start { lvStatus.set("Current threshold: " + max + " GB. You have 60s to change this value in this module's menu."); doEvery(interval, r checkIt); // allow 60 seconds after start to change max value } long usedMegabytes() { ret oshi_currentProcessResidentSize()/oneMegabyte(); } void checkIt enter { long megabytes = usedMegabytes(); lvStatus.set("Emergency restart enabled. Memory use: " + megabytes + "/" + max + " MB"); if (megabytes >= max) { dm_gc(); sleepSeconds(5); megabytes = usedMegabytes(); if (megabytes >= max) { localMechLog("Emergency shutdowns", "Emergency shutdown at " + localDateWithSeconds() + " because of too much memory use ("+ megabytes + " MB)"); dm_restartOS(); } } } }