Title: memoryview leaks references
Type: resource usage Stage:
Components: Interpreter Core Versions: Python 3.0
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, benjamin.peterson, pitrou, teoliphant
Priority: release blocker Keywords: patch

Created on 2008-08-28 11:00 by amaury.forgeotdarc, last changed 2008-09-01 15:10 by pitrou. This issue is now closed.

File name Uploaded Description Edit
memleak.patch pitrou, 2008-08-28 11:23
memleak2.patch pitrou, 2008-08-28 12:37
Messages (6)
msg72078 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-08-28 11:00
Two problems with memoryview:
- The buffer interface of memoryview leaks a reference:
    str(memoryview(b'text'), 'utf-8')

- memoryview does not implement tp_traverse and tp_clear, so reference
cycle cannot be collected, as with:

import gc
class MyBuf(bytes): pass

def f():
    buf = MyBuf(b'abc')
    m = memoryview(buf)
    buf.m = m

each call to f() leaks 6 references.
msg72080 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-08-28 11:23
Here is a patch. I feel a bit unsafe with the intended semantics of
getting a buffer on a memoryview object, but it fixes the leak.
msg72082 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-08-28 11:25
(I forgot to say, the patch is for the first problem only)
msg72086 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-08-28 12:37
Here is an aggregate patch addressing both problems. Please review.
msg72243 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-09-01 13:59
I think the patch looks good.
msg72261 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-09-01 15:10
Fixed in r66111.
Date User Action Args
2008-09-01 15:10:59pitrousetstatus: open -> closed
resolution: fixed
messages: + msg72261
2008-09-01 14:20:19benjamin.petersonsetkeywords: - needs review
2008-09-01 13:59:17benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg72243
2008-08-28 12:37:16pitrousetfiles: + memleak2.patch
messages: + msg72086
2008-08-28 11:25:41pitrousetmessages: + msg72082
2008-08-28 11:23:32pitrousetfiles: + memleak.patch
nosy: + pitrou, teoliphant
messages: + msg72080
components: + Interpreter Core
keywords: + patch, needs review
type: resource usage
2008-08-28 11:00:03amaury.forgeotdarccreate