fix(ChatViewModel): add deinit cleanup for NotificationCenter observers and timers #120
+7
−0
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.
fix(ChatViewModel): add deinit cleanup for NotificationCenter observers and timers
Summary
Added a
deinit
method toChatViewModel
to clean up NotificationCenter observers, timers, and Combine subscriptions when the view model is deallocated. Without this, resources would persist beyond the lifecycle of the instance, leading to memory leaks and unpredictable behavior.Problem
ChatViewModel
registers for system notifications during initialization using:It also creates:
nicknameSaveTimer
) in thenickname
setterdeliveryTrackerCancellable
) to track delivery statusPreviously, there was no
deinit
method, so none of these were cleaned up when the object was released. This could lead to:Fix
Added a
deinit
method to the class (within the primaryChatViewModel
declaration):This ensures proper cleanup when the view model is deallocated.
This: