Skip to content

Commit 489c0ed

Browse files
committed
WPF - Improve ChromiumWebBrowser Dispose
- RenderHandler wasn't being disposed at all - Used newer syntax for null Dispose calls
1 parent 050d354 commit 489c0ed

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

CefSharp.Wpf/ChromiumWebBrowser.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -673,11 +673,8 @@ private void InternalDispose(bool disposing)
673673
browser = null;
674674

675675
// Incase we accidentally have a reference to the CEF drag data
676-
if (currentDragData != null)
677-
{
678-
currentDragData.Dispose();
679-
currentDragData = null;
680-
}
676+
currentDragData?.Dispose();
677+
currentDragData = null;
681678

682679
PresentationSource.RemoveSourceChangedHandler(this, PresentationSourceChangedHandler);
683680
// Release window event listeners if PresentationSourceChangedHandler event wasn't
@@ -715,17 +712,18 @@ private void InternalDispose(bool disposing)
715712
CleanupElement.Unloaded -= OnCleanupElementUnloaded;
716713
}
717714

718-
if (managedCefBrowserAdapter != null)
719-
{
720-
managedCefBrowserAdapter.Dispose();
721-
managedCefBrowserAdapter = null;
722-
}
715+
managedCefBrowserAdapter?.Dispose();
716+
managedCefBrowserAdapter = null;
723717

724718
// LifeSpanHandler is set to null after managedCefBrowserAdapter.Dispose so ILifeSpanHandler.DoClose
725719
// is called.
726720
LifeSpanHandler = null;
727721

728-
WpfKeyboardHandler.Dispose();
722+
WpfKeyboardHandler?.Dispose();
723+
WpfKeyboardHandler = null;
724+
725+
RenderHandler?.Dispose();
726+
RenderHandler = null;
729727

730728
source = null;
731729
}

0 commit comments

Comments
 (0)