Issue 3608: memoryview constructor has no deallocator (original) (raw)

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:37 admin set github: 47858
2008-08-20 21:11:25 georg.brandl set status: open -> closedresolution: wont fix
2008-08-20 18:54:56 rupole set messages: +
2008-08-20 18:11:58 pitrou set messages: +
2008-08-20 18:04:34 rupole set messages: +
2008-08-20 09:43:29 pitrou set priority: normal
2008-08-20 09:43:17 pitrou set type: resource usage -> enhancementmessages: +
2008-08-19 23:12:18 benjamin.peterson set assignee: teoliphantnosy: + pitrou, teoliphant
2008-08-19 23:03:11 rupole set messages: +
2008-08-19 22:54:15 benjamin.peterson set nosy: + benjamin.petersonmessages: +
2008-08-19 22:50:38 rupole create