discord.py: Rewrite: Memory leak

`import discord from discord.ext import commands

bot = commands.AutoShardedBot(command_prefix=“prefix”)

bot.run(“token”)`

My bot has been leaking memory for quite a while now but now it’s in around 2.4k servers it’s becoming a much bigger issue, I’ve been through multiple steps to try and find out what the possible leak was and I haven’t found anything, so I decided to run the script above on the bots token to find out if that leaked memory and it did so I’ve came here to ask is there something I need to disable or do to try and stop the leak.

Extra info: Memory climbs to 1.5gb within 5 hours, the bot is in 2.4k servers running 2 shards

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 21 (9 by maintainers)

Most upvoted comments

With my experience of previously running a >200k guild AutoSharded - across multiple processes - discord.py bot, it’s the state/cache. @shikhir-arora explains it pretty well, with the exception that Python has a much larger object overhead than other languages.

I’ve done my own memory leak searching and couldn’t find anything that was obvious. Currently, my 170k guild bot starts with ~24gb of memory during a normal load day; it goes up to 32gb within two days.

If there is a deeper rooted memory leak though, I’d be open to performing any tests.

Did you even read the issue? There’s a grand total of 4 lines of code in the test bot that observes the memory leak. It is most certainly not the bot code.