Skip to content

Commit 7eae9fd

Browse files
committed
Add test to check for memory leaks
1 parent 375ca7c commit 7eae9fd

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

tests/ndarray/test_resize.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,18 @@ def test_expand_dims(shape, axis, chunks, blocks, fill_value):
6060
a = blosc2.expand_dims(a, axis=axis) # could lose ref to original array and thus dealloc data
6161
npa = np.expand_dims(npa, axis)
6262
assert a[()].shape == npa[()].shape # getitem fails if deallocate has happened
63+
64+
# Now check that garbage collecting works and there will be no memory leaks for views
65+
import sys
66+
67+
arr = np.arange(4)
68+
bloscarr_ = blosc2.asarray(arr)
69+
assert sys.getrefcount(arr) == sys.getrefcount(bloscarr_) # = 2
70+
71+
view = np.expand_dims(arr, 0)
72+
bloscview = blosc2.expand_dims(bloscarr_, 0)
73+
assert sys.getrefcount(arr) == sys.getrefcount(bloscarr_) # = 3
74+
75+
del view
76+
del bloscview
77+
assert sys.getrefcount(arr) == sys.getrefcount(bloscarr_) # = 2

0 commit comments

Comments
 (0)