Fix memory leaks due to un-closed thread pools and worlds

How did it take this long to realize the DhWorld objects were never being closed?
This commit is contained in:
James Seibel
2025-03-30 17:30:57 -05:00
parent 53bee4ad42
commit 6699b568df
3 changed files with 32 additions and 4 deletions
@@ -99,6 +99,11 @@ public class SharedApi
public static void setDhWorld(AbstractDhWorld newWorld)
{
AbstractDhWorld oldWorld = currentWorld;
if (oldWorld != null)
{
oldWorld.close();
}
currentWorld = newWorld;
// starting and stopping the DataRenderTransformer is necessary to prevent attempting to
@@ -89,7 +89,14 @@ public class ThreadPoolUtil
public static void setupThreadPools()
{
// thread pools
//==================//
// main thread pool //
//==================//
if (taskPicker != null)
{
taskPicker.shutdown();
}
taskPicker = new PriorityTaskPicker();
networkCompressionThreadPool = taskPicker.createExecutor();
@@ -98,8 +105,22 @@ public class ThreadPoolUtil
updatePropagatorThreadPool = taskPicker.createExecutor();
worldGenThreadPool = taskPicker.createExecutor();
// single thread pools
//=========================//
// standalone thread pools //
//=========================//
if (beaconCullingThreadPool != null)
{
beaconCullingThreadPool.shutdown();
}
beaconCullingThreadPool = ThreadUtil.makeSingleThreadPool(BEACON_CULLING_THREAD_NAME);
if (fullDataMigrationThreadPool != null)
{
fullDataMigrationThreadPool.shutdown();
}
fullDataMigrationThreadPool = ThreadUtil.makeSingleThreadPool(FULL_DATA_MIGRATION_THREAD_NAME);
}
@@ -39,8 +39,8 @@ public class DhClientWorld extends AbstractDhWorld implements IDhClientWorld
public final ClientOnlySaveStructure saveStructure;
public final ClientNetworkState networkState = new ClientNetworkState();
public ExecutorService dhTickerThread = ThreadUtil.makeSingleThreadPool("Client World Ticker Thread");
public EventLoop eventLoop = new EventLoop(this.dhTickerThread, this::_clientTick);
public final ExecutorService dhTickerThread = ThreadUtil.makeSingleThreadPool("Client World Ticker Thread");
public final EventLoop eventLoop = new EventLoop(this.dhTickerThread, this::_clientTick);
@@ -128,6 +128,8 @@ public class DhClientWorld extends AbstractDhWorld implements IDhClientWorld
{
this.networkState.close();
this.dhTickerThread.shutdownNow();
for (DhClientLevel dhClientLevel : this.levels.values())
{