MoBends icon indicating copy to clipboard operation
MoBends copied to clipboard

(1.12) Memory Leak: EntityBenderRegistry#entityToBenderMap

Open Meldexun opened this issue 4 years ago • 0 comments

Describe the bug Entries of the map EntityBenderRegistry#entityToBenderMap use entity instances as their keys which creates a memory leak. There are some methods for clearing the map but they only seem to be called when the config has changed or the refresh hotkey is used.

Aside from that I'm not sure why that map exists in the first place. I have looked at the class a bit and to me it seems that the entityClassToBenderMap should be enough and the entityToBenderMap is just rendundant.

This also looks very similar to the RenderManager#entityRenderMap from vanilla which can be accessed with RenderManager#getEntityClassRenderObject(Class<? extends Entity>). I think doing something similar here would be a good solution.

https://github.com/mobends/MoBends/blob/3b56b02e59fcf2d8571d3fedb6ceee8f8824ba05/src/main/java/goblinbob/mobends/core/bender/EntityBenderRegistry.java#L23

To Reproduce Steps to reproduce the behavior:

  1. Join a world
  2. Leave the world
  3. See WorldClient instance not being garbage collected

Context (please complete the following information):

  • Minecraft version: 1.12.2
  • Forge version: 14.23.5.2855
  • Mo' Bends version: 1.1.0

Meldexun avatar Dec 21 '21 00:12 Meldexun