Fix memory reset bug by petebankhead · Pull Request #1996 · qupath/qupath
Fixes #1946 (I hope).
This also changes the max memory preference from requiring the memory to be defined in GB to instead using a percentage of available memory. I think this is easier to reason about, and also means we can constrain it to be between 10% and 90%.
This is a bit convoluted, because we need to try to read the current max memory from the config - since we can't rely upon the preference being correct. For example, having duplicate QuPath installations where they have the same (major/minor) version would result in them using the same preference key, but having different config files. The config files are what matters for setting the memory during launch. Another reason the preference might not match the reality is if the config file was edited externally.
There are still ways to thwart this, e.g. using a config file that specifies the max memory multiple times or in different ways (e.g. using -Xmx) but I think that's tolerable.