yt-dlp: Memory leaks
Checklist
- I’m reporting a bug unrelated to a specific site
- I’ve verified that I’m running yt-dlp version 2021.12.01. (update instructions)
- I’ve checked that all provided URLs are alive and playable in a browser
- I’ve checked that all URLs and arguments with special characters are properly quoted or escaped
- I’ve searched the bugtracker for similar issues including closed ones. DO NOT post duplicates
- I’ve read the guidelines for opening an issue
Description
I embed yt-dlp in my app and it cause continuous memory consumption increasing.
Tried debug a little bit and i found that python gc can’t free some yt-dlp objects.
Calling gc.garbage
will return huge list of leaked objects
Verbose log
import gc
import yt_dlp as y
gc.set_debug(gc.DEBUG_UNCOLLECTABLE | gc.DEBUG_LEAK)
y.YoutubeDL().extract_info("https://www.youtube.com/watch?v=mIv2puMWFSc",download=False)
gc.collect()
print(gc.garbage)
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 1
- Comments: 23 (19 by maintainers)
Hello, I don’t know if I should’ve open a new issue but I also experience memory leaks with a more minimal example & they are bigger than 20MB over 1000 iterations.
To reproduce:
These are the results (all on
yt-dlp==2023.11.16
):Python 3.9 (with lazy extractors): 182KiB per iteration
Python 3.9 (without lazy extractors): 182KiB per iteration
Python 3.12 (with lazy extractors): 146KiB per iteration
Python 3.12 (without lazy extractors): 146KiB per iteration
+19010
s in outputs seem to be 10 timeslen(yt_dlp.YoutubeDL()._ies)
, but I couldn’t find why they leak.Yes, same.
The latest version (2024.03.10) fixed the memory leak for me, I no longer see memory increase.
@vinismarques @zackees see #8922 and check if #9032 resolves your memory leak issue
You are right about
DEBUG_SAVEALL
, but read docs again:gc.DEBUG_SAVEALL When set, ALL UNREACHABLE OBJECTS FOUND WILL BE APPENDED TO GARBAGE rather than being freed. This can be useful for debugging a leaking program.
~It will not be freed until program exit~(edit: some objects maybe but some objects may not) event if you will not setset_debug