Skip to content

Fix memory leak when setting opaque on Frame#2286

Merged
WyattBlue merged 1 commit into
PyAV-Org:mainfrom
lgeiger:opaque-leak
Jun 5, 2026
Merged

Fix memory leak when setting opaque on Frame#2286
WyattBlue merged 1 commit into
PyAV-Org:mainfrom
lgeiger:opaque-leak

Conversation

@lgeiger
Copy link
Copy Markdown
Contributor

@lgeiger lgeiger commented Jun 5, 2026

import resource
import av

def get_rss():
    return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss

print(f"Base RSS memory: {get_rss():,} bytes")

print("Running 1,000,000 iterations of setting .opaque...")
for i in range(1_000_000):
    frame = av.VideoFrame(16, 16, "yuv420p")
    frame.opaque = i  # This triggers the av_malloc in opaque.py
    del frame

print(f"Final RSS memory: {get_rss():,} bytes")

main:

Base RSS memory: 42,450,944 bytes
Running 1,000,000 iterations of setting .opaque...
Final RSS memory: 57,950,208 bytes

This PR:

Base RSS memory: 42,287,104 bytes
Running 1,000,000 iterations of setting .opaque...
Final RSS memory: 42,287,104 bytes

@WyattBlue WyattBlue merged commit 75e6854 into PyAV-Org:main Jun 5, 2026
7 checks passed
@lgeiger lgeiger deleted the opaque-leak branch June 5, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants