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 problem still existed in version 2.0.10 #80

Open
MLrookie opened this issue Mar 3, 2022 · 4 comments
Open

Memory leak problem still existed in version 2.0.10 #80

MLrookie opened this issue Mar 3, 2022 · 4 comments

Comments

@MLrookie
Copy link

MLrookie commented Mar 3, 2022

Memory leak problem still existed in version 2.0.10, but it is said thath it has been fixed in 2.0.10 according to README.md. If you run the following code, you will found that the memory of process quickly increase.

for _ in range(100000):
        webrtcvad.Vad(3)
@yaleimeng
Copy link

one Vad() object can deal many voice files, you don't need to create so many Vad() objetcs.
According to the cpu cores and threads, I think 8~32 is enough.

@willnufe
Copy link

This seems to be due to the issue of the vad_free function not being called properly in the pywebrtcvad.c file.
I made modifications to the code for testing.

  static void vad_free(PyObject* vadptr)
  {
    VadInst* handle = PyCapsule_GetPointer(vadptr, "WebRtcVadPtr");
    printf("vad_free\n");
    WebRtcVad_Free(handle);
  }
  
  static PyObject* vad_create(PyObject *self, PyObject *args)
  {
    VadInst *handle = WebRtcVad_Create();
    printf("vad_create\n");
    // PyObject *vadptr = PyCapsule_New(handle, "WebRtcVadPtr", vad_free);
    // return Py_BuildValue("O", vadptr);
    return PyCapsule_New(handle, "WebRtcVadPtr", vad_free);
  }
# testing
import webrtcvad
from tqdm import tqdm

for _ in tqdm(range(10)):
    print("im here begin")
    vad = webrtcvad.Vad(3)
    print("im here end")

    del vad  # This line of code needs to be added to free up memory
    print("im here del end")
    print("\n\n")

# res
"""
im here begin
vad_create
im here end
vad_free
im here del end

...
"""

If it is the original code, it will not print the 'vad_free', which means it will not release memory normally.
But I am not sure if this is the cause of the memory leak. Can someone provide verification?

@arkadijs
Copy link

Hi, any updates on this and PR #49?
Pooling VAD instances sometimes is not an option as reusing them across streams produces non-repeatable results, unfortunately.

@daanzu
Copy link

daanzu commented Sep 5, 2024

FYI, I have implemented this change in my fork at https://github.com/daanzu/py-webrtcvad-wheels .

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

5 participants