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);