From 25f522c539f40698e702af05b3cf89c835a65736 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 11 May 2024 09:25:57 -0400 Subject: [PATCH] Make sure no memory leaks --- src/engine/gameManager/BuildingManager.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index fcf7b158..9032880c 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -334,12 +334,25 @@ public enum BuildingManager { NPC hirelingNPC = (NPC) hireling; if (ForgeManager.vendorWorkOrderLookup.get(hirelingNPC) != null) + for (WorkOrder workOrder : ForgeManager.vendorWorkOrderLookup.get(hirelingNPC)) { workOrder.runCompleted.set(true); workOrder.vendor = null; + + // Remove any cooking items from collections + // to ensure we don't leak memory. + + for (Item item : workOrder.cooking) + ForgeManager.itemWorkOrderLookup.remove(item); + DbManager.WarehouseQueries.DELETE_WORKORDER(workOrder); } + + // Finally remove the NPC from ForgeManager + + ForgeManager.vendorWorkOrderLookup.remove(hirelingNPC); } + // Remove hireling from building building.getHirelings().remove(hireling);