Skip to content

Fix TrayService singleton resource leak on app shutdown#79

Open
murapadev with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-trayservice-dispose-issue
Open

Fix TrayService singleton resource leak on app shutdown#79
murapadev with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-trayservice-dispose-issue

Conversation

Copilot AI commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

TrayService implements Dispose() to release the tray icon, context menu, and associated resources, but it was never called — causing those resources to leak on every app exit.

Changes

  • App.axaml.cs: Subscribe to desktop.Exit to invoke TrayService.Instance.Dispose() during the app shutdown sequence.
// Dispose tray resources on exit; handler lifetime matches application lifetime.
desktop.Exit += (s, e) => TrayService.Instance.Dispose();

TrayService.Dispose() already handles hiding the icon, nulling the menu, calling TrayIcon.Dispose(), and resetting internal state — this change simply ensures it's wired into the shutdown path.

…ktop.Exit event

Agent-Logs-Url: https://github.com/murapadev/NeuralDeck/sessions/18ac77e2-1364-4719-8a06-6a7c28692cc7

Co-authored-by: murapadev <10557163+murapadev@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix TrayService singleton not disposed to prevent resource leaks Fix TrayService singleton resource leak on app shutdown Apr 10, 2026
Copilot AI requested a review from murapadev April 10, 2026 16:48
@murapadev murapadev marked this pull request as ready for review April 10, 2026 16:52
Copilot AI review requested due to automatic review settings April 10, 2026 16:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Wires TrayService.Dispose() into Avalonia’s desktop application shutdown so the tray icon/menu resources are released during app exit.

Changes:

  • Subscribe to IClassicDesktopStyleApplicationLifetime.Exit in App.OnFrameworkInitializationCompleted().
  • Dispose TrayService.Instance when the desktop lifetime exits.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread App.axaml.cs
Comment on lines +54 to +55
// Dispose tray resources on exit; handler lifetime matches application lifetime.
desktop.Exit += (s, e) => TrayService.Instance.Dispose();

Copilot AI Apr 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hooking TrayService disposal to desktop.Exit only runs on Avalonia’s normal shutdown path. The app also calls Environment.Exit(0) from the tray "Quit" menu (Services/TrayService.cs), which will bypass desktop.Exit and can still leave the tray icon/resources un-disposed. To match the PR description (“on every app exit”), route that quit action through the normal lifetime shutdown (or explicitly dispose TrayService before calling Environment.Exit).

Copilot uses AI. Check for mistakes.
murapadev pushed a commit that referenced this pull request Apr 10, 2026
, #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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CRITICAL] TrayService singleton not disposed — tray icon and menu resources leak

3 participants