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:
Damien George
2014-10-26 13:20:50 +00:00
parent c76af32575
commit de3c806965
2 changed files with 74 additions and 24 deletions

View 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))