Fix memory leak by using weak set for ArrayBackedEvent list ()

* use weak set for array backed events list

* use thread safe map

(cherry picked from commit 70be179cf3)
This commit is contained in:
BasiqueEvangelist 2023-01-31 11:54:42 +03:00 committed by modmuss50
parent 683b8893da
commit ae26bc3563

View file

@ -23,16 +23,19 @@ import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import java.util.Set;
import java.util.function.Function;
import com.google.common.collect.MapMaker;
import net.minecraft.util.Identifier;
import net.fabricmc.fabric.api.event.Event;
public final class EventFactoryImpl {
private static final List<ArrayBackedEvent<?>> ARRAY_BACKED_EVENTS = new ArrayList<>();
private static final Set<ArrayBackedEvent<?>> ARRAY_BACKED_EVENTS
= Collections.newSetFromMap(new MapMaker().weakKeys().makeMap());
private EventFactoryImpl() { }