Skip to content

Singleton MemoryError can hold traceback data and locals indefinitely #49687

Closed

Description

@pitrou
BPO 5437
Nosy @amauryfa, @pitrou, @avassalotti
Files
  • memerr.py
  • memerror.patch
  • memerror.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 2010-10-28.23:07:25.847>
    created_at = <Date 2009-03-08.01:19:49.933>
    labels = ['performance']
    title = 'Singleton MemoryError can hold traceback data and locals indefinitely'
    updated_at = <Date 2010-10-28.23:07:25.846>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2010-10-28.23:07:25.846>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-10-28.23:07:25.847>
    closer = 'pitrou'
    components = []
    creation = <Date 2009-03-08.01:19:49.933>
    creator = 'pitrou'
    dependencies = []
    files = ['13261', '15230', '19403']
    hgrepos = []
    issue_num = 5437
    keywords = ['patch']
    message_count = 10.0
    messages = ['83292', '83293', '83296', '89181', '94684', '110325', '112001', '119806', '119822', '119823']
    nosy_count = 4.0
    nosy_names = ['amaury.forgeotdarc', 'pitrou', 'alexandre.vassalotti', 'BreamoreBoy']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'resource usage'
    url = 'https://bugs.python.org/issue5437'
    versions = ['Python 3.1', 'Python 3.2']

    Activity

    1. pitrou commented on Mar 8, 2009

      @pitrou
      MemberAuthor

      The PyExc_MemoryErrorInst object is persistent and its members never get
      cleared. This means any local variable which gets caught in the
      traceback isn't deallocated until the next MemoryError (!). Sample
      script demonstrates this.

      (this doesn't seem to affect 2.x because the traceback isn't attached to
      the exception instance)

    2. pitrou commented on Mar 8, 2009

      @pitrou
      MemberAuthor

      The following patch fixes the case when the exception is discarded in
      Python, but not when e.g. PyErr_Clear() is used from C code.

    3. pitrou commented on Mar 8, 2009

      @pitrou
      MemberAuthor

      A proper fix would probably be to maintain a bunch of preallocated
      instances in a freelist rather than relying on an explicit singleton. It
      would enforce proper dereferencing and garbage collection semantics.

    4. avassalotti commented on Jun 10, 2009

      @avassalotti
      Member

      Honestly, I don't think it is a big issue. MemoryErrors are rare and
      typically cause the interpreter to shutdown.

      By the way, do you think the static PyExc_RecursionErrorInst object is
      affected by this bug?

    5. pitrou commented on Oct 29, 2009

      @pitrou
      MemberAuthor

      Here is a patch preallocating a freelist of MemoryErrors.

      To Alexandre: yes, PyExc_RecursionErrorInst probably has the same problem.

    6. BreamoreBoy commented on Jul 14, 2010

      BreamoreBoymannequin
      Mannequin

      Would someone please check out thie patch, it's mostly changes to C code that I'm not qualified to comment on.

    7. BreamoreBoy commented on Jul 29, 2010

      BreamoreBoymannequin
      Mannequin

      Changing priority as nobody appears to have lost any sleep over this issue.

    8. pitrou commented on Oct 28, 2010

      @pitrou
      MemberAuthor

      Updated patch against py3k.

    9. pitrou commented on Oct 28, 2010

      @pitrou
      MemberAuthor

      I can't manage to reproduce the issue with PyExc_RecursionErrorInst. It seems this instance is only used in a very select condition, that is, when the recursion limit is hit when trying to "normalize" an exception. Therefore, I will add a test without "fixing" anything.

    10. pitrou commented on Oct 28, 2010

      @pitrou
      MemberAuthor

      Patch with improved tests committed in r85896 (3.2) and r85898 (3.1).

    11. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      performancePerformance or resource usage

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions