mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 12:40:15 +01:00
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.
This commit is contained in:
18
tests/basics/memoryview_gc.py
Normal file
18
tests/basics/memoryview_gc.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# 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))
|
||||
Reference in New Issue
Block a user