You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gateway.logout() needs to be subscribed with subscribe or block in order to disconnect and begin to release resources. Can you check if the issue persists after adding that?
Beyond that, GatewayDiscordClient is an expensive resource, so if you need to reuse the token there are more efficient ways to do this. ObjectMapper (JacksonResources in D4J) can be reused in case you need to do this under multiple bot tokens.
Thanks. Adding .block() after .disconnect() fixes the issue (my 40m Xmx test did not crash after 25 iterations, so i stopped it)
Given it's expensive, I can try keeping my GatewayDiscordClient instance long lived and never logout. My app could run for months at a time, do you foresee issues with that approach?
No issues, that's the recommended approach for a general use case. You would only have to spin multiple GatewayDiscordClients if you need to use different bot tokens.
However if you only need the guild members, you don't require a real-time bot connection (Gateway). Could just use the REST client like this:
To Reproduce:
Run this code in a loop on Java17 with -Xmx40m. For me it only goes four iterations and hits OOM on the fifth.
Expected Behavior:
I expected logout() to release any resources, and when my GatewayDiscordClient instance gets GC'd then its fully cleaned up.
Actual Behavior:
There are statically retained objects created each time running that code.
Version:
3.2.3
Other:
My server app has been dying with OOME since incorporating discord4j. I use version 3.2.3.
Eclipse MAT showed this in the heap dump:
These ObjectMapper instances are being created each time thru the loop.
This shows the paths to GC roots for one of the instances:
The text was updated successfully, but these errors were encountered: