!7 // Note: Deadlock solving happens in OS main too, so it will not be // lost if GC is turned off here. cmodule2 GarbageCollection { bool on = true; transient IF0 cond = () -> on; start { doEvery(1.0, 60.0, r updateMe); } visualize { JLabel lblTime = jCenteredLabel(" "); awtEvery(lblTime, 1000, r { long last = lastRegularGC(); setText(lblTime, last == 0 ? "No GC yet" : "Time since last GC: " + iround(elapsedSeconds_timestamp(last)) + " s"); }); ret vstackWithSpacing( toolTip("On = Perform a Java garbage collection every minute", centerCheckBox(dm_fieldCheckBox("GC On", 'on))), lblTime); } void update { //print("GC: " + on); if (dm_osHasField gc_subcondition()) { // new method - keeps weak hash map cleaning if (dm_getOS gc_subcondition() != cond) { dm_setOS gc_subcondition(cond); infoBoxAndProgramLog((on ? "Enabling" : "Disabling") + " Garbage Collection"); } updateModuleName(); } else { print("Legacy method"); // legacy method bool has = hasRegularGC(); if (has != on) { infoBoxAndProgramLog((on ? "Enabling" : "Disabling") + " Garbage Collection"); if (on) regularGC_firstDelay(1000); else noRegularGC(); } } } void updateModuleName { setModuleName("Garbage collector is " + (on ? "On" : "Off")); } }