Description
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.