Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak on Linux #323

Open
se7enXF opened this issue Oct 24, 2024 · 2 comments
Open

Memory leak on Linux #323

se7enXF opened this issue Oct 24, 2024 · 2 comments

Comments

@se7enXF
Copy link

se7enXF commented Oct 24, 2024

  • version: 0.6.0
  • Windows: pycharm 2023.3.1 Community Edition, python 3.9
  • Linux: RHEl 7.5, python 3.9
  • problem: memory leak on Linux but not on Windows

Read frame codes:

from decord import VideoReader
reader = VideoReader(url)
frame_count = len(reader)
frame_ids = np.linespace(0, frame_count  - 1, 10, dtype=int).tolist()
frames = reader.get_batch(frame_ids).asnumpy()

I use decord to read video frames in a Fastapi view. There is no memory leak on Windows when debuging in pycharm, but leak on Linux when start python script directly. Memory only raise when requeset the api, without any signs of decreasing.

To debug memory leak, I call reader.del() after read frames. It works on Windows but meets Segmentation fault on Linux.

Finally, I use numpy.zeros() creating frames to replace decord reading frames, there is no memory leak.

Someone help me please.

@ITerydh
Copy link

ITerydh commented Nov 22, 2024

i also find memory leak on Linux

@NeighborhoodCoding
Copy link

NeighborhoodCoding commented Dec 9, 2024

Simply calling del reader may not reliably clean up resources on Linux. Instead:

Set reader = None after reading frames.
Call gc.collect() to prompt Python’s garbage collector to free memory.
For example:

from decord import VideoReader, cpu
import gc

def read_frames(url):
reader = VideoReader(url, ctx=cpu(0))
frame_count = len(reader)
frame_ids = np.linspace(0, frame_count - 1, 10, dtype=int).tolist()
frames = reader.get_batch(frame_ids).asnumpy()
# Release references
del frames
reader = None
gc.collect()
return True

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

No branches or pull requests

3 participants