I have a social network, where I can place comments on posts. I havce implemented this using a ReactionController that handles API calls for a post that has an event that indicates that the API call finished.
My code goes like this (in my "timeline" controller, when the UI asks me to place a reaction):
public void PlaceReaction(string reaction) {
var reactionController = new ReactionController(post);
reactionController.DishUpdatedEvent += (updatedPost) => {
// Notify the UI
UIThreadDispatcher.Invoke(() => SinglePostUpdatedEvent?.Invoke(updatedPost));
};
reactionController.PlaceReaction(reaction);
}
and in my ReactionController:
// Saved to API
UIThreadDispatcher.Invoke(() => PostUpdatedEvent?.Invoke(_post));
I am afraid my liberal use of events may cause the ReactionController to remain in memory, but I only want it to stay in memory for the duration of the call, until the event is fired. Will this act like I want it to or do I have a memory leak?