!7 cmodule FrontendUnloader > DynPrintLogAndEnabled { switchable double timeout = 60.0; // in seconds after last activity switchable double checkInterval = 10.0; switchable bool actuallyUnload; start { dm_doEvery(checkInterval, r check); } void check enter { if (!enabled) ret; // stayLoaded -> module ID. also has a null key! new MultiMap mm; for (O mod : vmBus_queryAll chatBotFrontend()) { Bool b = cast dm_call(mod, 'shouldStayLoaded, timeout); mm.put(b, dm_moduleID(mod)); } if (empty(mm)) ret; int nPlus = l(mm.get(true)); int nMinus = l(mm.get(false)); int nIndifferent = l(mm.get(null)); print("Results: " + nPlus + " should stay loaded, " + nMinus + " can be unloaded, " + nIndifferent + " indifferent"); if (actuallyUnload) unloadModules(mm.get(false)); } void unloadModules(LS modules) { if (empty(modules)) ret; print("Unloading " + nModules(modules)); dm_pcallAll(modules, 'deleteYourself); } }