Skip to content

Commit 5779b5e

Browse files
committed
Release events. Finally release the dockable windows.
1 parent d7b2504 commit 5779b5e

File tree

9 files changed

+59
-7
lines changed

9 files changed

+59
-7
lines changed

RetailCoder.VBE/API/ParserState.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public interface IParserStateEvents
3838
[ComDefaultInterface(typeof(IParserState))]
3939
[ComSourceInterfaces(typeof(IParserStateEvents))]
4040
[EditorBrowsable(EditorBrowsableState.Always)]
41-
public class ParserState : IParserState
41+
public class ParserState : IParserState, IDisposable
4242
{
4343
private const string ClassId = "28754D11-10CC-45FD-9F6A-525A65412B7A";
4444
private const string ProgId = "Rubberduck.ParserState";
@@ -132,5 +132,10 @@ public Declaration[] UserDeclarations
132132
//[return: MarshalAs(UnmanagedType.SafeArray/*, SafeArraySubType = VarEnum.VT_VARIANT*/)]
133133
get { return _userDeclarations; }
134134
}
135+
136+
public void Dispose()
137+
{
138+
_state.StateChanged -= _state_StateChanged;
139+
}
135140
}
136141
}

RetailCoder.VBE/Extension.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,13 @@ public void OnStartupComplete(ref Array custom)
6969

7070
public void OnDisconnection(ext_DisconnectMode RemoveMode, ref Array custom)
7171
{
72+
var addin = _kernel.Get<AddIn>();
73+
7274
_app.Shutdown();
7375
_kernel.Dispose();
76+
77+
Marshal.FinalReleaseComObject(addin);
78+
GC.SuppressFinalize(addin);
7479
}
7580
}
7681
}

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace Rubberduck.Navigation.CodeExplorer
1717
{
18-
public class CodeExplorerViewModel : ViewModelBase
18+
public class CodeExplorerViewModel : ViewModelBase, IDisposable
1919
{
2020
private readonly FolderHelper _folderHelper;
2121
private readonly RubberduckParserState _state;
@@ -360,5 +360,11 @@ private void ExecuteRemoveComand(object param)
360360

361361
_externalRemoveCommand.Execute(param);
362362
}
363+
364+
public void Dispose()
365+
{
366+
_state.StateChanged -= ParserState_StateChanged;
367+
_state.ModuleStateChanged -= ParserState_ModuleStateChanged;
368+
}
363369
}
364370
}

RetailCoder.VBE/UI/CodeInspections/InspectionResultsViewModel.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
namespace Rubberduck.UI.CodeInspections
2323
{
24-
public class InspectionResultsViewModel : ViewModelBase, INavigateSelection
24+
public class InspectionResultsViewModel : ViewModelBase, INavigateSelection, IDisposable
2525
{
2626
private readonly RubberduckParserState _state;
2727
private readonly IInspector _inspector;
@@ -341,5 +341,10 @@ private bool CanExecuteCopyResultsCommand(object parameter)
341341
{
342342
return !IsBusy && _results != null && _results.Any();
343343
}
344+
345+
public void Dispose()
346+
{
347+
_state.StateChanged -= _state_StateChanged;
348+
}
344349
}
345350
}

RetailCoder.VBE/UI/Command/MenuItems/RubberduckCommandBar.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ public void Dispose()
141141
return;
142142
}
143143

144+
_state.StateChanged -= State_StateChanged;
145+
144146
_refreshButton.Delete();
145147
_selectionButton.Delete();
146148
_statusButton.Delete();

RetailCoder.VBE/UI/DockableToolwindowPresenter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ protected virtual void Dispose(bool disposing)
116116
if (UserControl != null)
117117
{
118118
UserControl.Dispose();
119+
GC.SuppressFinalize(UserControl);
119120
}
120121

121122
if (_window != null)
122123
{
123-
Marshal.ReleaseComObject(_window);
124+
_window.Close();
125+
Marshal.FinalReleaseComObject(_window);
124126
}
125127
}
126128
}

RetailCoder.VBE/UI/SourceControl/SourceControlViewViewModel.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
namespace Rubberduck.UI.SourceControl
1919
{
20-
public class SourceControlViewViewModel : ViewModelBase
20+
public class SourceControlViewViewModel : ViewModelBase, IDisposable
2121
{
2222
private readonly VBE _vbe;
2323
private readonly RubberduckParserState _state;
@@ -559,5 +559,10 @@ public ICommand LoginGridCancelCommand
559559
return _loginGridCancelCommand;
560560
}
561561
}
562+
563+
public void Dispose()
564+
{
565+
_state.StateChanged -= _state_StateChanged;
566+
}
562567
}
563568
}

RetailCoder.VBE/UI/ToDoItems/ToDoExplorerViewModel.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Rubberduck.UI.ToDoItems
1515
{
16-
public class ToDoExplorerViewModel : ViewModelBase, INavigateSelection
16+
public class ToDoExplorerViewModel : ViewModelBase, INavigateSelection, IDisposable
1717
{
1818
private readonly RubberduckParserState _state;
1919
private readonly IGeneralConfigService _configService;
@@ -147,5 +147,10 @@ private IEnumerable<ToDoItem> GetItems()
147147
{
148148
return _state.AllComments.SelectMany(GetToDoMarkers);
149149
}
150+
151+
public void Dispose()
152+
{
153+
_state.StateChanged -= _state_StateChanged;
154+
}
150155
}
151156
}

Rubberduck.Parsing/VBA/RubberduckParser.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
namespace Rubberduck.Parsing.VBA
2222
{
23-
public class RubberduckParser : IRubberduckParser
23+
public class RubberduckParser : IRubberduckParser, IDisposable
2424
{
2525
public RubberduckParserState State
2626
{
@@ -570,5 +570,22 @@ private void ResolveReferences(DeclarationFinder finder, VBComponent component,
570570
_state.SetModuleState(component, state);
571571
Debug.WriteLine("'{0}' is {1} (thread {2})", component.Name, _state.GetModuleState(component), Thread.CurrentThread.ManagedThreadId);
572572
}
573+
574+
public void Dispose()
575+
{
576+
State.ParseRequest -= ReparseRequested;
577+
State.StateChanged -= StateOnStateChanged;
578+
579+
if (_resolverTokenSource != null)
580+
{
581+
_resolverTokenSource.Dispose();
582+
}
583+
584+
if (_central != null)
585+
{
586+
_central.Cancel();
587+
_central.Dispose();
588+
}
589+
}
573590
}
574591
}

0 commit comments

Comments
 (0)