micropython/tests/basics/memoryview_gc.py
Damien George de3c806965 py: Fix memoryview referencing so it retains ptr to original buffer.
This way, if original parent object is GC'd, the memoryview still points
to the underlying buffer data so that buffer is not GC'd.
2014-10-26 13:20:50 +00:00

19 lines
351 B
Python

# test memoryview retains pointer to original object/buffer
b = bytearray(10)
m = memoryview(b)[1:]
for i in range(len(m)):
m[i] = i
# reclaim b, but hopefully not the buffer
b = None
import gc
gc.collect()
# allocate lots of memory
for i in range(100000):
[42, 42, 42, 42]
# check that the memoryview is still what we want
print(list(m))