Calling RegisterLocal
with the same callback more than once will result in the Dispatcher subscribing the callback multiple times
#16
Labels
bug
Something isn't working
Currently, in the
EventDispatcher
object we have aDictionary<string, List<Subscription>> eventSubscriptions
which associates the name of an event with a list of subscriptions (which in turn contain actions) that get called whenever this event happens. This means that if aRegisterLocal
is invoked more than once for the same pair ofevent_name + action
then whenever said event happens, the action will get executed multiple times (once for each time it appears in the list).For example, this can happen in the case in which
RegisterLocal
is called in the constructor of an object, but said objects is instantiated multiple times. (As a note for anyone reading this: this shouldn't really happen since every object that subscribes it's methods to the eventManager viaregisterLocal
should be a singleton. Otherwise, a memory leak may happen since a reference to the objects is owned by the EventDispatcher, and said objects would never get garbage collected).A possible solution to this issue can be that of using a
HashSet
to hold the subscriptions of an event in theEventDispatcher
instead of aList
. We should look a bit more into this, but in principle, theHashSet
shouldn't allow repeated entries of theSubscription
entity.An example of what I mean (dotnet fidddle can be seen here):
The text was updated successfully, but these errors were encountered: