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

allow use of a weak hashmap in the EventBus for listeners #2930

Closed
xenoterracide opened this issue Aug 30, 2017 · 3 comments
Closed

allow use of a weak hashmap in the EventBus for listeners #2930

xenoterracide opened this issue Aug 30, 2017 · 3 comments
Labels
package=eventbus type=enhancement Make an existing feature better

Comments

@xenoterracide
Copy link

xenoterracide commented Aug 30, 2017

The EventBus currently requires you to unregister/manually garbage collect. Making it responsible for Listener lifecycles. We have a problem where we have to manually deregister in order to avoid memory leaks, but the only hooks for us to do this also create subtle bugs. What'd we'd really like is for listeners to be stored as weak keys, so if the listener could otherwise be garbage collected it would be. This way the eventbus can be "global" or "session" and you can have listeners that come and go. If you need persistent listeners you can use your DI system, whether that be Spring, Guice, etc.

https://github.com/bennidi/mbassador is an eventbus that works this way, and there is some consideration on switching to it on our part, but the long term stability of that project is questionable.

what I would suggest for backwards compatibility is storing the listeners in your own cache, and then adding a constructor or static method that allows the creation of an eventbus with a custom CacheBuilder allowing us to say CacheBuilder.weakKeys(...) or whatever. It's possible you could go for much less flexible and simply make it a boolean or something.

@xenoterracide xenoterracide changed the title allow use of a weak hashmap in the EventBus allow use of a weak hashmap in the EventBus for listeners Aug 30, 2017
@perceptron8
Copy link
Contributor

@xenoterracide
Copy link
Author

xenoterracide commented Aug 30, 2017

probably a dupe of #807, though I don't agree with the solution proposed there (and it's hard to follow). The problem all comes down to having listeners that have a shorter lifecycle than the eventbus, and that don't have good hooks of their own to deregister.

@cgdecker cgdecker added package=eventbus type=enhancement Make an existing feature better labels Sep 12, 2017
@ronshapiro
Copy link
Contributor

Closing this in favor of the duplicate issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package=eventbus type=enhancement Make an existing feature better
Projects
None yet
Development

No branches or pull requests

4 participants