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

* use weak set for array backed events list

* use thread safe map
This commit is contained in:
BasiqueEvangelist 2023-01-31 11:54:42 +03:00 committed by GitHub
parent eff3bcb77a
commit 70be179cf3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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() { }