Skip to content

fix: Implement IDisposable on ShortcutService and dispose on app exit#78

Open
murapadev with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-shortcutservice-idisposable
Open

fix: Implement IDisposable on ShortcutService and dispose on app exit#78
murapadev with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-shortcutservice-idisposable

Conversation

Copilot AI commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

ShortcutService held a Window reference and accumulated KeyBinding registrations with no cleanup path, leaking resources on app shutdown.

Changes

  • ShortcutService: Added : IDisposable to the class declaration — the Dispose() method already existed (calls UnregisterAll() + nulls _window) but the interface was never declared.
  • App.axaml.cs: Wired ShortcutService.Instance?.Dispose() into IClassicDesktopStyleApplicationLifetime.Exit to guarantee cleanup on shutdown.
desktop.Exit += (_, _) => ShortcutService.Instance?.Dispose();

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:

  • av-build-tel-api-v1.avaloniaui.net
    • Triggering command: /usr/share/dotnet/dotnet dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/avalonia.buildservices/0.0.29/tools/netstandard2.0/runtimeconfig.json /home/REDACTED/.nuget/packages/avalonia.buildservices/0.0.29/tools/netstandard2.0/Avalonia.BuildServices.Collector.dll 20' --output-dircredential.username (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix ShortcutService resource leak by implementing IDisposable fix: Implement IDisposable on ShortcutService and dispose on app exit Apr 10, 2026
Copilot AI requested a review from murapadev April 10, 2026 16:49
@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

Adds a guaranteed cleanup path for ShortcutService on application shutdown by formally implementing IDisposable and invoking disposal from the Avalonia desktop lifetime exit hook.

Changes:

  • Declared ShortcutService : IDisposable (the Dispose() method already existed).
  • Hooked ShortcutService disposal into IClassicDesktopStyleApplicationLifetime.Exit.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
Services/ShortcutService.cs Declares IDisposable on ShortcutService to match its existing Dispose() implementation.
App.axaml.cs Disposes ShortcutService on desktop app exit to ensure keybindings/window references are cleared during shutdown.

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

Comment thread App.axaml.cs

desktop.MainWindow = mainWindow;

desktop.Exit += (_, _) => ShortcutService.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.

ShortcutService.Instance is non-nullable and lazily creates the singleton (_instance ??= new ShortcutService()). Using ShortcutService.Instance?.Dispose() will still instantiate the service during shutdown even if it was never used, and the null-conditional is redundant. If the intent is to dispose only when already created, consider adding a static DisposeInstance()/TryGetInstance() (or exposing a Current/MaybeInstance that returns _instance) and call that from desktop.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] ShortcutService not IDisposable — KeyBinding resources leak

3 participants