-
-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Description
Describe the issue:
The following code crashes during process shutdown with the error:
*** Reference count error detected: an attempt was made to deallocate the dtype 5 (i) ***
I am only able to reproduce this under Python 3.12 on Mac and Linux, not Python 3.13 or 3.14.
Reproduce the code example:
import numpy as np
class MyArray:
def __init__(self, val):
self.val = val
def __array__(self, dtype=None, copy=None):
return self.val.__array__(dtype=dtype, copy=copy)
x = np.array(-1, dtype=np.int32)
x = MyArray(x)
np.array(x)Error message:
*** Reference count error detected: an attempt was made to deallocate the dtype 5 (i) ***Python and NumPy Versions:
2.3.2
3.12.10 (main, Apr 9 2025, 04:03:51) [Clang 20.1.0 ]
Runtime Environment:
[{'numpy_version': '2.3.2',
'python': '3.12.10 (main, Apr 9 2025, 04:03:51) [Clang 20.1.0 ]',
'uname': uname_result(system='Linux', node='redacted', release='6.12.32-redacted-amd64', version='#1 SMP PREEMPT_DYNAMIC Debian 6.12.32-redacted (2025-06-26)', machine='x86_64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2'],
'not_found': ['AVX512F',
'AVX512CD',
'AVX512_KNL',
'AVX512_KNM',
'AVX512_SKX',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL',
'AVX512_SPR']}},
{'architecture': 'Haswell',
'filepath': '/.../home/phawkins/venv/py312/lib/python3.12/site-packages/numpy.libs/libscipy_openblas64_-8fb3d286.so',
'internal_api': 'openblas',
'num_threads': 64,
'prefix': 'libscipy_openblas',
'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.30'}]
Context for the issue:
Distilled out of a reference counting error found while working on JAX.