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

Use weakrefs in add_event_handler? #318

Closed
Tracked by #387
almarklein opened this issue Dec 23, 2022 · 2 comments
Closed
Tracked by #387

Use weakrefs in add_event_handler? #318

almarklein opened this issue Dec 23, 2022 · 2 comments
Labels
question Further information is requested

Comments

@almarklein
Copy link
Member

By registering callbacks via add_event_handler, references to objects are stored and can prevent objects from being cleaned up. Is this behavior that we want, or should we use weakrefs?

@almarklein almarklein added the question Further information is requested label Dec 23, 2022
@almarklein almarklein mentioned this issue Oct 23, 2023
30 tasks
@almarklein
Copy link
Member Author

Some options:

  1. Store the given callback with a weakref. This would break e.g. lambdas and closures, so nah.
  2. Store the callback, but (only) use a weakref if its a method. This could kinda work, but it can also feel inconsistent, especially since a closure can also hold a reference to an object.
  3. Just store all callbacks by reference. If this is a problem, the caller can use weakrefs in a way that works for the use-case at hand.

I'm leaning hard towards option 3. Created #398 to "implement" that.

@Korijn
Copy link
Collaborator

Korijn commented Oct 24, 2023

I support that preference for option 3. It doesn't need to be solved here necessarily.

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

No branches or pull requests

2 participants