8000 BUG: Memleak in frombuffer() when applied to QByteArray · Issue #28398 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Memleak in frombuffer() when applied to QByteArray #28398

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

Closed
coells opened this issue Feb 27, 2025 · 2 comments
Closed

BUG: Memleak in frombuffer() when applied to QByteArray #28398

coells opened this issue Feb 27, 2025 · 2 comments
Labels
00 - Bug 57 - Close? Issues which may be closable unless discussion continued

Comments

@coells
Copy link
coells commented Feb 27, 2025

Describe the issue:

I'm facing an issue with memleaks when numpy.frombuffer() is combined with Qt QByteArray.

Ihere is an instance of QByteArray() in the code I attached. Once frombuffer() is called, refcount of QByteArray increases but never decreases again.

In large (Qt-based) app, there are millions of these calls in a longer period of time which causes major memory leak in size of GBs.

Reproduce the code example:

import gc
import numpy as np
from pyqtgraph.Qt import QtCore
import sys


if __name__ == '__main__':
    n = 1024

    backstore = QtCore.QByteArray()
    backstore.resize(n * 8)

    print(sys.getrefcount(backstore))
    np.frombuffer(backstore, dtype=[('x', '>f8')], count=n)
    print(sys.getrefcount(backstore))
    np.frombuffer(backstore, dtype=[('x', '>f8')], count=n)
    print(sys.getrefcount(backstore))
    np.frombuffer(backstore, dtype=[('x', '>f8')], count=n)
    print(sys.getrefcount(backstore))
    gc.collect()
    print(sys.getrefcount(backstore))

Error message:

-

Python and NumPy Versions:

2.1.3
3.12.9 | packaged by conda-forge | (main, Feb 14 2025, 08:00:06) [GCC 13.3.0]

Runtime Environment:

[{'numpy_version': '2.1.3',
'python': '3.12.9 | packaged by conda-forge | (main, Feb 14 2025, 08:00:06) '
'[GCC 13.3.0]',
'uname': uname_result(system='Linux', node='qminersstudy4.lonx.tower-research.com', release='5.4.191-el7.lime.2.x86_64', version='#1 SMP Thu Jul 14 19:09:52 EDT 2022', machine='x86_64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2',
'AVX512F',
'AVX512CD',
'AVX512_SKX'],
'not_found': ['AVX512_KNL',
'AVX512_KNM',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL',
'AVX512_SPR']}},
{'filepath': '/apps/qminers/conda/envs/shared/lib/libmkl_rt.so.2',
'internal_api': 'mkl',
'num_threads': 1,
'prefix': 'libmkl_rt',
'threading_layer': 'intel',
'user_api': 'blas',
'version': '2024.2.2-Product'},
{'filepath': '/apps/qminers/conda/envs/shared/lib/libomp.so',
'internal_api': 'openmp',
'num_threads': 1,
'prefix': 'libomp',
'user_api': 'openmp',
'version': None}]

Context for the issue:

Qt-based (and pyqtgraph) app leaks GBs of RAM every night just due to the leak.

@seberg
Copy link
Member
seberg commented Feb 27, 2025

I can't reproduce it. I would assume this is a pyqtgraph bug. Just replace the frombuffer call with memoryview and see what happens. It should do the same thing.

@seberg seberg added the 57 - Close? Issues which may be closable unless discussion continued label Feb 27, 2025
@coells
Copy link
Author
coells commented Feb 28, 2025

You're right, memoryview causes memory leak, too. Thanks, I'm closing the issue.

@coells coells closed this as completed Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug 57 - Close? Issues which may be closable unless discussion continued
Projects
None yet
Development

No branches or pull requests

2 participants
0