From acecbede8ef9124112d452e840ea0733a4f5d9ff Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 21 Mar 2026 16:57:38 -0500 Subject: [PATCH] fix phantom log when there is sufficient memory --- .../objects/pooling/PhantomArrayListPool.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/objects/pooling/PhantomArrayListPool.java b/core/src/main/java/com/seibel/distanthorizons/core/util/objects/pooling/PhantomArrayListPool.java index f648abb4d..f266006ca 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/objects/pooling/PhantomArrayListPool.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/objects/pooling/PhantomArrayListPool.java @@ -185,24 +185,34 @@ public class PhantomArrayListPool else { // this reference is pointing to null, - // the checkout must have been garbage collected, - // that means we don't have enough memory + // the checkout was garbage collected if (!lowMemoryWarningLogged) { - lowMemoryWarningLogged = true; + // Complain if there isn't much free ram. + // Some garbage collectors may remove our soft references unnecessarily + // even when there is free space, and this should prevent the warning from + // popping up unnecessarily. - String message = MinecraftTextFormat.ORANGE + "Distant Horizons: Insufficient memory detected." + MinecraftTextFormat.CLEAR_FORMATTING + "\n" + + long freeMemoryBytes = Runtime.getRuntime().freeMemory(); + + long expectedFreeMemoryBytes = 1_073_741_824 /* 1 Gibibyte */ / 8; // 128 MibiBytes + if (freeMemoryBytes < expectedFreeMemoryBytes) + { + lowMemoryWarningLogged = true; + + String message = MinecraftTextFormat.ORANGE + "Distant Horizons: Insufficient memory detected." + MinecraftTextFormat.CLEAR_FORMATTING + "\n" + "This may cause stuttering or crashing. \n" + "Potential causes: \n" + "1. your allocated memory isn't high enough \n" + "2. your DH CPU preset is too high \n" + "3. your DH quality preset is too high \n" + "4. you have other memory hungry mod(s)"; - - LOGGER.warn(message); - if (Config.Common.Logging.Warning.showPoolInsufficientMemoryWarning.get()) - { - ClientApi.INSTANCE.showChatMessageNextFrame(message); + + LOGGER.warn(message); + if (Config.Common.Logging.Warning.showPoolInsufficientMemoryWarning.get()) + { + ClientApi.INSTANCE.showChatMessageNextFrame(message); + } } }