Skip to content

Reloading an extension module always leaks #47917

Closed

Description

@amauryfa
BPO 3667
Nosy @loewis, @warsaw, @amauryfa, @benjaminp
Files
  • import-leak.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 = 'https://github.com/benjaminp'
    closed_at = <Date 2008-09-04.02:28:32.515>
    created_at = <Date 2008-08-24.20:54:59.499>
    labels = ['release-blocker']
    title = 'Reloading an extension module always leaks'
    updated_at = <Date 2008-09-04.02:28:32.514>
    user = 'https://github.com/amauryfa'

    bugs.python.org fields:

    activity = <Date 2008-09-04.02:28:32.514>
    actor = 'benjamin.peterson'
    assignee = 'benjamin.peterson'
    closed = True
    closed_date = <Date 2008-09-04.02:28:32.515>
    closer = 'benjamin.peterson'
    components = []
    creation = <Date 2008-08-24.20:54:59.499>
    creator = 'amaury.forgeotdarc'
    dependencies = []
    files = ['11289']
    hgrepos = []
    issue_num = 3667
    keywords = ['patch', 'needs review']
    message_count = 4.0
    messages = ['71867', '72085', '72466', '72467']
    nosy_count = 4.0
    nosy_names = ['loewis', 'barry', 'amaury.forgeotdarc', 'benjamin.peterson']
    pr_nums = []
    priority = 'release blocker'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue3667'
    versions = ['Python 3.0']

    Activity

    1. amauryfa commented on Aug 24, 2008

      @amauryfa
      ContributorAuthor

      With python2.6, reloading extension modules does not always leak memory:

      Python 2.6b2+ (trunk, Aug 19 2008, 23:45:24) [MSC v.1500 32 bit (Intel)]
      on win32
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import sys
      [34467 refs]
      >>> import audioop; del sys.modules['audioop']
      [34677 refs]
      >>> import audioop; del sys.modules['audioop']
      [34677 refs]

      But with 3.0, reloading audioop leaks 60 references every time (seen in
      test_unittest):

      Python 3.0b3+ (py3k, Aug 24 2008, 21:56:40) [MSC v.1500 32 bit (Intel)]
      on win32
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import sys
      [42018 refs]
      >>> import audioop; del sys.modules['audioop']
      [42257 refs]
      >>> import audioop; del sys.modules['audioop']
      [42317 refs]
      >>> import audioop; del sys.modules['audioop']
      [42377 refs]
      >>> import audioop; del sys.modules['audioop']
      [42437 refs]
      >>> import audioop; del sys.modules['audioop']
      [42497 refs]

      OK, many things cannot be reinitialized for C-written modules (static
      variables &co), this is not the case for audioop. Furthermore, I thought
      that the new module API was to support proper cleanup of modules

    2. amauryfa commented on Aug 28, 2008

      @amauryfa
      ContributorAuthor

      The fix is actually simple: _PyImport_FindExtension() used to return a
      borrowed reference, the "strong" reference being stored in the
      PyImport_GetModuleDict() dictionary. All paths should behave the same.

      See attached patch.

      (for unit tests, run for example
      regrtest.py -R:: test_site
      )

    3. warsaw commented on Sep 4, 2008

      @warsaw
      Member

      The patch looks good. Benjamin will commit this.

    4. assigned and unassigned on Sep 4, 2008
    5. benjaminp commented on Sep 4, 2008

      @benjaminp
      Contributor

      Fixed in r66204.

    6. 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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions