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

Commit e9d1f5a

Browse files
committed
Trying to get the dispose pattern right.
1 parent 6a5e5fc commit e9d1f5a

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/GitHub.UI.Reactive/Controls/ViewBase.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public class ViewBase<TInterface, TImplementor> : ViewBase, IView, IViewFor<TInt
105105
"ViewModel", typeof(TInterface), typeof(TImplementor), new PropertyMetadata(null));
106106

107107
IDisposable subscriptions;
108+
bool disposed;
108109

109110
/// <summary>
110111
/// Initializes a new instance of the <see cref="ViewBase{TInterface, TImplementor}"/> class.
@@ -213,10 +214,15 @@ public void Dispose()
213214
/// </summary>
214215
protected virtual void Dispose(bool disposing)
215216
{
216-
if (disposing)
217+
if (!disposed)
217218
{
218-
subscriptions?.Dispose();
219-
subscriptions = null;
219+
if (disposing)
220+
{
221+
subscriptions?.Dispose();
222+
subscriptions = null;
223+
}
224+
225+
disposed = true;
220226
}
221227
}
222228
}

src/GitHub.VisualStudio/UI/Views/PullRequestListView.xaml.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ protected override void Dispose(bool disposing)
6262
{
6363
base.Dispose(disposing);
6464

65-
if (disposed) return;
66-
67-
if (disposing)
65+
if (!disposed)
6866
{
69-
open.Dispose();
70-
create.Dispose();
67+
if (disposing)
68+
{
69+
open.Dispose();
70+
create.Dispose();
71+
}
72+
7173
disposed = true;
7274
}
7375
}

0 commit comments

Comments
 (0)