Skip to content

Commit

Permalink
Use the available physical memory as upper memory limit for the slide…
Browse files Browse the repository at this point in the history
…r in the launcher. (#1433)

* Use the available physical memory as upper memory limit for the slider in the launcher.

* Update launcher/src/se/llbit/chunky/launcher/ui/ChunkyLauncherController.java

Co-authored-by: Maximilian Stiede <[email protected]>

---------

Co-authored-by: Maximilian Stiede <[email protected]>
  • Loading branch information
leMaik and Maximilian Stiede authored Oct 27, 2023
1 parent 47b7f25 commit 355f76d
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;
Expand Down Expand Up @@ -114,7 +115,7 @@ public String getLabel(VersionInfo item) {

memoryLimit.setTooltip("Maximum Java heap space in megabytes (MiB).\n"
+ "Limited by the available memory in your computer.");
memoryLimit.setRange(512, 1 << 14);
memoryLimit.setRange(512, getUpperMemoryLimitMb());
memoryLimit.makeLogarithmic();
memoryLimit.set(settings.memoryLimit);
memoryLimit.onValueChange(value -> settings.memoryLimit = value);
Expand Down Expand Up @@ -296,6 +297,16 @@ public void updateLauncher(Consumer<String> errorCallback, Consumer<LauncherInfo
updateChecker.start();
}

private int getUpperMemoryLimitMb() {
try {
return (int) (((com.sun.management.OperatingSystemMXBean) ManagementFactory
.getOperatingSystemMXBean()).getTotalPhysicalMemorySize() / 1024 / 1024);
} catch (Exception e) {
// fallback for JDKs that don't have com.sun.management.OperatingSystemMXBean
return 1 << 14; // 16 GiB
}
}

/**
* Updates the launcher settings when opening the main launcher window.
*
Expand Down

0 comments on commit 355f76d

Please sign in to comment.