discord service: prevent event handlers from being gc'd

This commit is contained in:
Adam
2019-01-01 10:24:47 -05:00
parent 758f95c517
commit 553a690d23

View File

@@ -57,6 +57,8 @@ public class DiscordService implements AutoCloseable
private ScheduledExecutorService executorService;
private DiscordRPC discordRPC;
// Hold a reference to the event handlers to prevent the garbage collector from deleting them
private final DiscordEventHandlers discordEventHandlers = new DiscordEventHandlers();
/**
* Initializes the Discord service, sets up the event handlers and starts worker thread that will poll discord
@@ -77,7 +79,6 @@ public class DiscordService implements AutoCloseable
return;
}
final DiscordEventHandlers discordEventHandlers = new DiscordEventHandlers();
discordEventHandlers.ready = this::ready;
discordEventHandlers.disconnected = this::disconnected;
discordEventHandlers.errored = this::errored;