Skip to content

ndarray.ctypes creates a reference cycle #13808

@pijyoi

Description

@pijyoi

Reading attribute "ctypes.data" from an ndarray causes a leak.
version <= 1.14.5 doesn't leak
version >= 1.16.2 leaks
latest 1.16.4 leaks

Reproducing code example:

import numpy as np
import sys

print(np.version.full_version)

data = np.empty(8192)

before = sys.getrefcount(data)
data.ctypes.data
after = sys.getrefcount(data)
print(before, after)

assert before==after

Error message:

File "/mnt/d/code/python/test_numpy_leak.py", line 17, in
assert before==after
AssertionError

Numpy/Python version information:

1.16.4 3.6.8 (default, Jan 14 2019, 11:02:34)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]


Summary (@seberg) 2019-12-03

This has been partially fixed by gh-14469; There are still issues here, although they are mainly issues with upstream ctypes creating deep reference cycles.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions