You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
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.
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 sayCacheBuilder.weakKeys(...)
or whatever. It's possible you could go for much less flexible and simply make it a boolean or something.The text was updated successfully, but these errors were encountered: