Fix CancellationTokenSource leak: wire ChatViewModel.Dispose() to app shutdown#76
Conversation
Agent-Logs-Url: https://github.com/murapadev/NeuralDeck/sessions/e83f29f2-f0a4-4c1f-a730-59507ea9c3d0 Co-authored-by: murapadev <10557163+murapadev@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Ensures ChatViewModel.Dispose() is invoked during application shutdown so its background CancellationTokenSource instances don’t remain alive for the lifetime of the process.
Changes:
- Add
IDisposabletoMainWindowViewModeland forward disposal toChatViewModel. - Hook Avalonia desktop lifetime
Exitevent to dispose theMainWindowViewModelon app shutdown.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| ViewModels/MainWindowViewModel.cs | Implements IDisposable and disposes/releases ChatViewModel on shutdown. |
| App.axaml.cs | Calls MainWindowViewModel.Dispose() from desktop.Exit to guarantee cleanup at application exit. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
, #79) - MainWindowViewModel: implement IDisposable, dispose ChatViewModel - ShortcutService: add IDisposable interface declaration - App.OnExit: dispose TrayService, ShortcutService, MainWindowViewModel Cherry-picked from copilot branches: 8be25e3 (TrayService), b353ef1 (ShortcutService), 0f80c4d (ChatViewModel)
|
@copilot resolve the merge conflicts in this pull request |
…odel-dispose-leak # Conflicts: # App.axaml.cs Co-authored-by: murapadev <10557163+murapadev@users.noreply.github.com>
Merged Main had already evolved to include a comprehensive Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
ChatViewModelimplementsIDisposableto cancel and dispose_pollCts(background connection poller) and_chatCts(active chat request), butDispose()was never called — leaving bothCancellationTokenSourceinstances open for the lifetime of the process.Changes
MainWindowViewModel— implementsIDisposable;Dispose()delegates toChatViewModel?.Dispose(), nulls the reference, and unsubscribes fromConfigService.Instance.ConfigChangedApp.axaml.cs— hooksdesktop.ShutdownRequestedto prepare the window service for shutdown, anddesktop.Exitvia a dedicatedOnExithandler that comprehensively disposesOllamaService,TrayService,ShortcutService, andMainWindowViewModel(which in turn disposesChatViewModel)