Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memoryview leaks references #47962

Closed
amauryfa opened this issue Aug 28, 2008 · 6 comments
Closed

memoryview leaks references #47962

amauryfa opened this issue Aug 28, 2008 · 6 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage release-blocker

Comments

@amauryfa
Copy link
Member

BPO 3712
Nosy @amauryfa, @pitrou, @benjaminp
Files
  • memleak.patch
  • memleak2.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2008-09-01.15:10:59.133>
    created_at = <Date 2008-08-28.11:00:03.648>
    labels = ['interpreter-core', 'release-blocker', 'performance']
    title = 'memoryview leaks references'
    updated_at = <Date 2008-09-01.15:10:59.132>
    user = 'https://github.com/amauryfa'

    bugs.python.org fields:

    activity = <Date 2008-09-01.15:10:59.132>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-09-01.15:10:59.133>
    closer = 'pitrou'
    components = ['Interpreter Core']
    creation = <Date 2008-08-28.11:00:03.648>
    creator = 'amaury.forgeotdarc'
    dependencies = []
    files = ['11286', '11290']
    hgrepos = []
    issue_num = 3712
    keywords = ['patch']
    message_count = 6.0
    messages = ['72078', '72080', '72082', '72086', '72243', '72261']
    nosy_count = 4.0
    nosy_names = ['teoliphant', 'amaury.forgeotdarc', 'pitrou', 'benjamin.peterson']
    pr_nums = []
    priority = 'release blocker'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'resource usage'
    url = 'https://bugs.python.org/issue3712'
    versions = ['Python 3.0']

    @amauryfa
    Copy link
    Member Author

    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
        gc.collect();gc.collect();gc.collect()

    each call to f() leaks 6 references.

    @pitrou
    Copy link
    Member

    pitrou commented Aug 28, 2008

    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.

    @pitrou pitrou added interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage labels Aug 28, 2008
    @pitrou
    Copy link
    Member

    pitrou commented Aug 28, 2008

    (I forgot to say, the patch is for the first problem only)

    @pitrou
    Copy link
    Member

    pitrou commented Aug 28, 2008

    Here is an aggregate patch addressing both problems. Please review.

    @benjaminp
    Copy link
    Contributor

    I think the patch looks good.

    @pitrou
    Copy link
    Member

    pitrou commented Sep 1, 2008

    Fixed in r66111.

    @pitrou pitrou closed this as completed Sep 1, 2008
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage release-blocker
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants