Skip to content

Commit c408990

Browse files
Fix Memory Leak w/ Entity Render State (#17)
Uses WeakHashMap instead of HashMap in EntityUtils for the ENTITY_RENDER_STATE map, since it is never cleared. It will now clear when out of scope.
1 parent 71c819d commit c408990

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/main/java/btw/mixces/animatium/util/EntityUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
import net.minecraft.world.entity.Entity;
2929
import org.jetbrains.annotations.Nullable;
3030

31-
import java.util.HashMap;
31+
import java.util.WeakHashMap;
3232

3333
public final class EntityUtils {
3434
private static final ThreadLocal<@Nullable HumanoidRenderState> HUMAN_RENDER_STATE = ThreadLocal.withInitial(() -> null);
35-
private static final HashMap<EntityRenderState, Entity> STATE_TO_ENTITY = new HashMap<>();
35+
private static final WeakHashMap<EntityRenderState, Entity> STATE_TO_ENTITY = new WeakHashMap<>();
3636

3737
public static void setEntityByState(EntityRenderState state, Entity entity) {
3838
STATE_TO_ENTITY.put(state, entity);

0 commit comments

Comments
 (0)