fix: memory leaks (surprisingly a lot)
can't believe i forgot to remove some elements....... especially in the query plugin, which is used A LOT by the tracked core, wows....... most of the leaks are caused by me not clearing the transactions IDs map, back in the days i didn't even know i have to do those since i didn't know i have to manage memory stuff
This commit is contained in:
@@ -81,6 +81,8 @@ public class EvalPlugin {
|
||||
final CompletableFuture<EvalOutput> future = futures.get(id);
|
||||
|
||||
future.complete(new EvalOutput(isError, output));
|
||||
|
||||
futures.remove(id);
|
||||
});
|
||||
|
||||
socket.connect();
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
public class QueryPlugin extends Bot.Listener {
|
||||
private final Bot bot;
|
||||
|
||||
private int nextTransactionId = 0;
|
||||
private long nextTransactionId = 0;
|
||||
private final Map<Long, CompletableFuture<String>> transactions = new HashMap<>();
|
||||
private final List<UUID> ids = new ArrayList<>();
|
||||
|
||||
@@ -48,12 +48,14 @@ public class QueryPlugin extends Bot.Listener {
|
||||
|
||||
if (!(children.getFirst() instanceof TextComponent)) return true;
|
||||
|
||||
final long transactionId = Integer.parseInt(((TextComponent) children.getFirst()).content());
|
||||
final long transactionId = Long.parseLong(((TextComponent) children.getFirst()).content());
|
||||
|
||||
if (!transactions.containsKey(transactionId)) return true;
|
||||
|
||||
final CompletableFuture<String> future = transactions.get(transactionId);
|
||||
|
||||
transactions.remove(transactionId);
|
||||
|
||||
if (children.size() == 1) {
|
||||
future.complete(null);
|
||||
} else {
|
||||
|
||||
@@ -29,6 +29,7 @@ public class TabCompletePlugin extends Bot.Listener {
|
||||
|
||||
final CompletableFuture<ClientboundCommandSuggestionsPacket> future = new CompletableFuture<>();
|
||||
transactions.put(transactionId, future);
|
||||
|
||||
return future;
|
||||
}
|
||||
|
||||
@@ -38,6 +39,10 @@ public class TabCompletePlugin extends Bot.Listener {
|
||||
}
|
||||
|
||||
public void packetReceived (ClientboundCommandSuggestionsPacket packet) {
|
||||
transactions.get(packet.getTransactionId()).complete(packet);
|
||||
final int id = packet.getTransactionId();
|
||||
|
||||
transactions.get(id).complete(packet);
|
||||
|
||||
transactions.remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user