After using Qupath for several years, I just discovered this extremely powerful little script. Basically, it solves almost all memory issues when running scripts in batch mode, and frankly should be the default mode for all batch mode scripts so that memory is not overwhelmed, as accumulated RAM usage in batch mode is a really frequent issue and causes so many crashes. In future versions I wish there was e.g. a check-box “Clear memory between each batch processed image” in the script window, or a separate option “Run for project (clear memory between images)”. Just a suggestion.
I now put this at the end of all my scripts before I run them in batch mode, and basically has removed most problems with RAM and QuPath:
Thread.sleep(100)
// Try to reclaim whatever memory we can, including emptying the tile cache
javafx.application.Platform.runLater {
getCurrentViewer().getImageRegionStore().cache.clear()
System.gc()
}
Thread.sleep(100)