This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: memoryview constructor has no deallocator
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 3.0
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: teoliphant Nosy List: benjamin.peterson, pitrou, rupole, teoliphant
Priority: normal Keywords:

Created on 2008-08-19 22:50 by rupole, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (7)
msg71495 - (view) Author: Roger Upole (rupole) Date: 2008-08-19 22:50
When using PyMemoryView_FromMemory to create a new object, you have to
pass in a preallocated buffer.  However, there's no way to specify a
routine to free the memory, and it leaks when the object is destroyed.
msg71496 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-08-19 22:54
PyMemoryView_FromMemory doesn't exist. Do you mean
PyMemoryView_FromBuffer or PyMemoryView_FromObject?
msg71498 - (view) Author: Roger Upole (rupole) Date: 2008-08-19 23:03
Well it existed up until a couple hours ago ;).
Looks like it was recently changed to PyMemoryView_FromBuffer.
However, it still has the same issue.
msg71526 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-08-20 09:43
Well, this is not a bug in itself. Memoryview objects are designed to
give access to a memory area backed by another object - they don't "own"
the memory by themselves (in the sense that you e.g. own a reference to
a PyObject).

Please note by the way that the Py_buffer struct now has a reference to
the original object, the "obj" field. PyBuffer_FillInfo() will incref
it, and PyBuffer_Release() will decref it again. However, it you set
this field to NULL, you are responsible for doing your own reference
management.

I agree that it may be nice to support your use case, but I'm not sure
what the semantics should be. For clarity, perhaps it should be a
derived class of memoryview.
msg71562 - (view) Author: Roger Upole (rupole) Date: 2008-08-20 18:04
As background, what I need is an equivalent of
PyBuffer_New(size), which creates an object that manages its
own buffer memory, and is not based on another object at all.
msg71563 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-08-20 18:11
> As background, what I need is an equivalent of
> PyBuffer_New(size), which creates an object that manages its
> own buffer memory, and is not based on another object at all.

Well, you can create either a bytes or bytearray object with an
internal buffer of the desired length. Then you'll be able to create a
memoryview out of it.
msg71567 - (view) Author: Roger Upole (rupole) Date: 2008-08-20 18:54
Aha, thanks.  I'll go that route for now.
History
Date User Action Args
2022-04-11 14:56:37adminsetgithub: 47858
2008-08-20 21:11:25georg.brandlsetstatus: open -> closed
resolution: wont fix
2008-08-20 18:54:56rupolesetmessages: + msg71567
2008-08-20 18:11:58pitrousetmessages: + msg71563
2008-08-20 18:04:34rupolesetmessages: + msg71562
2008-08-20 09:43:29pitrousetpriority: normal
2008-08-20 09:43:17pitrousettype: resource usage -> enhancement
messages: + msg71526
2008-08-19 23:12:18benjamin.petersonsetassignee: teoliphant
nosy: + pitrou, teoliphant
2008-08-19 23:03:11rupolesetmessages: + msg71498
2008-08-19 22:54:15benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg71496
2008-08-19 22:50:38rupolecreate