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

About weakref #157

Open
adrientetar opened this issue Dec 30, 2017 · 0 comments
Open

About weakref #157

adrientetar opened this issue Dec 30, 2017 · 0 comments

Comments

@adrientetar
Copy link
Contributor

defcon uses weakrefs to e.g. keep a reference to parent objects, but:

  • weakref.proxy could be used instead of weakref.ref, to spare the need for manual dereferencing.
  • I think weakrefs are not needed, and even that removing them would be a feature. Since version 2 the python GC can track cycles, so circular references only serve to tie object lifetimes, which I think is salutary in the case of parent refs. Consider the following code:
def giveMeGlyphA(path):
    font = Font(path)
    return font["A"]

glyph = giveMeGlyphA("/my/font")
glyph.font

Currently with weakrefs glyph.font would return None, whereas a strong reference would keep the font alive (until both font and glyph no longer have references). If the font's got multiple layers, here you could still access them rather than end up with an orphaned glyph etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant