mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-14 06:24:29 +01:00
Merge pull request #4108 from KJP12/mc1.18/forge/pr/memleak
Use a WeakHashMap in WorldAttached to prevent memory leaks
This commit is contained in:
commit
0b8e6760be
@ -2,9 +2,9 @@ package com.simibubi.create.foundation.utility;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
@ -22,7 +22,9 @@ public class WorldAttached<T> {
|
||||
|
||||
public WorldAttached(Function<LevelAccessor, T> factory) {
|
||||
this.factory = factory;
|
||||
attached = new HashMap<>();
|
||||
// Weak key hashmaps prevent worlds not existing anywhere else from leaking memory.
|
||||
// This is only a fallback in the event that unload events fail to fire for any reason.
|
||||
attached = new WeakHashMap<>();
|
||||
allMaps.add(new WeakReference<>(attached));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user