Memoryview Methods

memoryview.release()

End this view’s access to the exported buffer. Releasing a view can remove exporter restrictions such as bytearray resizing, but other live views or exports can keep those restrictions active. Repeated release calls are allowed. Most data access and conversion operations on a released view raise ValueError. Use a with block for deterministic release; do not rely on garbage collection timing. Release does not erase the underlying bytes.

Formal Syntax & Structure

python syntaxpython
view.release()

Return Value

None

No value; invalidates this view.

Working Example

Example Snippetpython
data = bytearray(b"AB")view = memoryview(data)print(view.release())data.append(67)print(data)try:    view[0]except ValueError:    print("released")
Python Reference