Skip to content

Commit

Permalink
Fix minor memory leaks (#258)
Browse files Browse the repository at this point in the history
* Fix memory leak caused by mob spawner items

* Use a weak hash map instead of manually clearing the map

* Clear manager reference to prevent holding a WorldClient reference through the GUI

* Revert "Use a weak hash map instead of manually clearing the map"

This reverts commit 91bb997.
  • Loading branch information
embeddedt authored Jun 6, 2022
1 parent d20a80a commit de2b2ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/codechicken/nei/ClientHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ public void tickEvent(TickEvent.ClientTickEvent event) {
lastworld = null;
else if (gui instanceof GuiSelectWorld)
NEIClientConfig.reloadSaves();
else if(gui == null) {
/* prevent WorldClient reference being held in the Gui */
NEIController.manager = null;
}
}
lastGui = gui;
}
Expand Down Expand Up @@ -328,6 +332,8 @@ public void loadWorld(World world, boolean fromServer) {

if (!Minecraft.getMinecraft().isSingleplayer())//wait for server to initiate in singleplayer
NEIClientConfig.loadWorld("remote/" + ClientUtils.getServerIP().replace(':', '~'));

ItemMobSpawner.clearEntityReferences(world);
}

lastworld = world;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/codechicken/nei/ItemMobSpawner.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public static EntityLiving getEntity(int ID) {
return e;
}

public static void clearEntityReferences(World newWorld) {
entityHashMap.values().removeIf(e -> e.worldObj != newWorld);
}

private void setDefaultTag(ItemStack itemstack) {
if (!IDtoNameMap.containsKey(itemstack.getItemDamage()))
itemstack.setItemDamage(idPig);
Expand Down

0 comments on commit de2b2ec

Please sign in to comment.