Skip to content

Commit aade1ca

Browse files
committed
Change GC suppression on DockableWindowHost. Should be safer.
1 parent 4f04338 commit aade1ca

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

RetailCoder.VBE/UI/DockableWindowHost.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using System.Windows.Forms;
66
using Rubberduck.Common.WinAPI;
77
using Rubberduck.VBEditor;
8+
using Rubberduck.VBEditor.WindowsApi;
9+
using User32 = Rubberduck.Common.WinAPI.User32;
810

911
namespace Rubberduck.UI
1012
{
@@ -52,6 +54,7 @@ private struct LParam
5254

5355
private IntPtr _parentHandle;
5456
private ParentWindow _subClassingWindow;
57+
private GCHandle _thisHandle;
5558

5659
internal void AddUserControl(UserControl control, IntPtr vbeHwnd)
5760
{
@@ -63,7 +66,7 @@ internal void AddUserControl(UserControl control, IntPtr vbeHwnd)
6366
//since we have to inherit from UserControl we don't have to keep handling window messages until the VBE gets
6467
//around to destroying the control's host or it results in an access violation when the base class is disposed.
6568
//We need to manually call base.Dispose() ONLY in response to a WM_DESTROY message.
66-
GC.KeepAlive(this);
69+
_thisHandle = GCHandle.Alloc(this, GCHandleType.Normal);
6770

6871
if (control != null)
6972
{
@@ -143,7 +146,7 @@ protected override void DefWndProc(ref Message m)
143146
//See the comment in the ctor for why we have to listen for this.
144147
if (m.Msg == (int) WM.DESTROY)
145148
{
146-
base.Dispose(true);
149+
_thisHandle.Free();
147150
return;
148151
}
149152
base.DefWndProc(ref m);

0 commit comments

Comments
 (0)