diff options
| author | Rapptz <[email protected]> | 2019-11-18 19:24:33 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2019-11-18 19:24:33 -0500 |
| commit | d8e47b08a275f446f42f485f31ccd6d035bcf908 (patch) | |
| tree | dd8a0fa9ddd13f346ffdb8d36849a7b034d4621d | |
| parent | Add changelog for 1.2.5 (diff) | |
| download | discord.py-d8e47b08a275f446f42f485f31ccd6d035bcf908.tar.xz discord.py-d8e47b08a275f446f42f485f31ccd6d035bcf908.zip | |
Manually trigger GC in cases of large deallocations.
| -rw-r--r-- | discord/state.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/discord/state.py b/discord/state.py index 622a4780..2c302197 100644 --- a/discord/state.py +++ b/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()) |