◐ Shell
clean mode source ↗

Message 170675 - Python tracker

> You would need to call memory_release(). Perhaps we can just expose it on the
> C-API level as PyMemoryView_Release().

Should PyMemoryView_Release() release the _PyManagedBufferObject by doing mbuf_release(view->mbuf) even if view->mbuf->exports > 0?

Doing

  Py_TYPE(view->mbuf)->tp_clear((PyObject *)view->mbuf);

seems to have the desired effect of causing ValueError when I try to access any associated memoryview.

>  3) A piece of memory needs to be packaged as a memoryview with automatic
>     cleanup in mbuf_dealloc():
>
>        PyMemoryView_FromBufferWithCleanup() (proposed in msg169613)

Maybe this should also handle decrefing the base object (given a flag PyManagedBuffer_FreeObj).  I do worry about creating memoryviews that survive deallocation of the base object.