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

Reloading an extension module always leaks #47917

Closed
amauryfa opened this issue Aug 24, 2008 · 4 comments
Closed

Reloading an extension module always leaks #47917

amauryfa opened this issue Aug 24, 2008 · 4 comments
Assignees

Comments

@amauryfa
Copy link
Member

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']

    @amauryfa
    Copy link
    Member Author

    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

    @amauryfa
    Copy link
    Member Author

    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
    )

    @warsaw
    Copy link
    Member

    warsaw commented Sep 4, 2008

    The patch looks good. Benjamin will commit this.

    @warsaw warsaw assigned benjaminp and unassigned loewis Sep 4, 2008
    @benjaminp
    Copy link
    Contributor

    Fixed in r66204.

    @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
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants