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

class member varibles assigned member functions create a circular reference #89020

Closed
cliffcordeiro mannequin opened this issue Aug 7, 2021 · 2 comments
Closed

class member varibles assigned member functions create a circular reference #89020

cliffcordeiro mannequin opened this issue Aug 7, 2021 · 2 comments
Labels
3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage

Comments

@cliffcordeiro
Copy link
Mannequin

cliffcordeiro mannequin commented Aug 7, 2021

BPO 44857

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 2021-08-07.02:34:55.458>
created_at = <Date 2021-08-07.02:20:59.937>
labels = ['interpreter-core', 'invalid', '3.8', 'performance']
title = 'class member varibles assigned member functions create a circular reference'
updated_at = <Date 2021-08-07.02:34:55.457>
user = 'https://bugs.python.org/cliffcordeiro'

bugs.python.org fields:

activity = <Date 2021-08-07.02:34:55.457>
actor = 'cliff.cordeiro'
assignee = 'none'
closed = True
closed_date = <Date 2021-08-07.02:34:55.458>
closer = 'cliff.cordeiro'
components = ['Interpreter Core']
creation = <Date 2021-08-07.02:20:59.937>
creator = 'cliff.cordeiro'
dependencies = []
files = []
hgrepos = []
issue_num = 44857
keywords = []
message_count = 2.0
messages = ['399165', '399166']
nosy_count = 1.0
nosy_names = ['cliff.cordeiro']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'resource usage'
url = 'https://bugs.python.org/issue44857'
versions = ['Python 3.8']

@cliffcordeiro
Copy link
Mannequin Author

cliffcordeiro mannequin commented Aug 7, 2021

This class is not collected by the gc without a custom __del__ method to del or assign None to self.fn:

import gc

class Leak:
    def __init__(self):
        self.fn = self.x

    def x(self):
        pass


gc.set_debug(gc.DEBUG_SAVEALL)

l = Leak()
del l
gc.collect()

for item in gc.garbage:
    print(item)

@cliffcordeiro cliffcordeiro mannequin added 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage labels Aug 7, 2021
@cliffcordeiro
Copy link
Mannequin Author

cliffcordeiro mannequin commented Aug 7, 2021

It looks like the collector does detect the cycle and that's why it ends up in garbage with gc.DEBUG_SAVEALL set. Sorry about that.

@cliffcordeiro cliffcordeiro mannequin closed this as completed Aug 7, 2021
@cliffcordeiro cliffcordeiro mannequin added the invalid label Aug 7, 2021
@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
3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage
Projects
None yet
Development

No branches or pull requests

0 participants