Browse Source

Manually trigger GC in cases of large deallocations.

feature/ext-tasks
Rapptz 5 years ago
parent
commit
d8e47b08a2
  1. 10
      discord/state.py

10
discord/state.py

@ -33,6 +33,7 @@ import logging
import math
import weakref
import inspect
import gc
from .guild import Guild
from .activity import _ActivityTag
@ -117,6 +118,11 @@ class ConnectionState:
self._private_channels_by_user = {}
self._messages = self.max_messages and deque(maxlen=self.max_messages)
# In cases of large deallocations the GC should be called explicitly
# To free the memory more immediately, especially true when it comes
# to reconnect loops which cause mass allocations and deallocations.
gc.collect()
def process_listeners(self, listener_type, argument, result):
removed = []
for i, listener in enumerate(self._listeners):
@ -210,6 +216,10 @@ class ConnectionState:
del guild
# Much like clear(), if we have a massive deallocation
# then it's better to explicitly call the GC
gc.collect()
@property
def emojis(self):
return list(self._emojis.values())

Loading…
Cancel
Save