Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 5bcc9f4

Browse files
committed
Plug some leaks
We were totally leaking like a sieve on event subscriptions to the connection manager.
1 parent cc866ba commit 5bcc9f4

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/GitHub.App/Controllers/UIController.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using NullGuard;
1818
using ReactiveUI;
1919
using Stateless;
20+
using System.Collections.Specialized;
2021

2122
namespace GitHub.Controllers
2223
{
@@ -36,6 +37,7 @@ enum Trigger { Cancel = 0, Auth = 1, Create = 2, Clone = 3, Publish = 4, Next, F
3637
readonly StateMachine<UIViewType, Trigger> machine;
3738
Subject<UserControl> transition;
3839
UIControllerFlow currentFlow;
40+
NotifyCollectionChangedEventHandler connectionAdded;
3941

4042
[ImportingConstructor]
4143
public UIController(IUIProvider uiProvider, IRepositoryHosts hosts, IExportFactoryProvider factory,
@@ -238,10 +240,11 @@ public void Start([AllowNull] IConnection connection)
238240
{
239241
if (!loggedin && currentFlow != UIControllerFlow.Authentication)
240242
{
241-
connectionManager.Connections.CollectionChanged += (s, e) => {
242-
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
243+
connectionAdded = (s, e) => {
244+
if (e.Action == NotifyCollectionChangedAction.Add)
243245
uiProvider.AddService(typeof(IConnection), e.NewItems[0]);
244246
};
247+
connectionManager.Connections.CollectionChanged += connectionAdded;
245248
}
246249

247250
machine.Configure(UIViewType.None)
@@ -278,6 +281,9 @@ protected virtual void Dispose(bool disposing)
278281
Debug.WriteLine("Disposing ({0})", GetHashCode());
279282
disposables.Dispose();
280283
transition?.Dispose();
284+
if (connectionAdded != null)
285+
connectionManager.Connections.CollectionChanged -= connectionAdded;
286+
connectionAdded = null;
281287
disposed = true;
282288
}
283289
}

src/GitHub.VisualStudio/TeamExplorer/Connect/GitHubConnectSection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ protected override void Dispose(bool disposing)
344344
{
345345
if (!disposed)
346346
{
347+
connectionManager.Connections.CollectionChanged -= RefreshConnections;
347348
if (Repositories != null)
348349
Repositories.CollectionChanged -= UpdateRepositoryList;
349350
disposed = true;

0 commit comments

Comments
 (0)