[issue9789] Explicit buffer release for memoryview objects

Nick Coghlan report at bugs.python.org
Tue Sep 7 14:53:15 CEST 2010

New submission from Nick Coghlan <ncoghlan at gmail.com>:

memoryview objects currently offer no way to explicitly release the underlying buffer.

This may cause problems for mutable objects that are locked while PEP 3118 buffer references remain unreleased (e.g. in 3.2, io.BytesIO supports getbuffer() for direct access to the underlying memory, but disallows resizing until the associated memoryview goes away).

This isn't too bad in CPython due to explicit refcounting, but may be an issue when using other implementations since the time between release of the last reference and actual garbage collection is indeterminate. For example, the new test_getbuffer in the BytesIOMixin class in the test suite relies on "del buf" promptly releasing the underlying PEP 3118 buffer, which may not be the case on other implementations.

So there are two separate questions here:
1. Whether or not to add an explicit "release()" method to memoryview objects (this would be sufficient to address the problem)
2. Whether or not to add direct context management support to memoryview objects (this isn't really necessary, since a short context manager can do the same thing, but may be a nice convenience)

Nosy list members added based on relevant python-dev discussion where GvR previously nixed part 2 of the idea. At the time, I hadn't really separated the two questions properly in my mind, but I suspect the failing to do something about the first one will prove problematic in the long run (or even the short run, as the test suite issue suggests).

messages: 115753
nosy: gvanrossum, ncoghlan, pitrou
priority: normal
severity: normal
status: open
title: Explicit buffer release for memoryview objects
type: feature request
versions: Python 3.2

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list