Issue619 - Provide method to unregister events #625
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
In Issue 619 it was reported by a user that there was no way to unregister events from the state machine. This leads to a memory leak in long running applications if you no longer want to be notified of
transitionortransition completedevents.Solution
Provide a way to unregister from both synchronous and asynchronous events. To successfully unregister callbacks, callers must maintain a reference to the original callback to ensure that it is cleared up. Otherwise, they can simply call
stateMachine.UnregisterAllCallbacks()in order to remove all callbacks (no reference needed).Documentation has been updated to reflect these new methods and the
OnOffExampleprogram has been tweaked to demonstrate registering and unregistering from callback events.Changes
OnOffExampleprogram to demonstrate the usage of the added APIs in the state machine.UnregisterAllmethod has been added to remove all callbacks at once with no reference pointer needed.OnTransitionedEventTest.csclass to specifically test theOnTransitionedEvent.csclass. These tests provide coverage for the entire functionality of the transition event class.