Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions CefSharp.OffScreen/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,8 @@ protected virtual void Dispose(bool disposing)

if (disposing)
{
browser = null;
IsBrowserInitialized = false;

if (managedCefBrowserAdapter != null)
{
managedCefBrowserAdapter.Dispose();
managedCefBrowserAdapter = null;
}

// Don't reference event listeners any longer:
AddressChanged = null;
BrowserInitialized = null;
Expand All @@ -374,6 +367,14 @@ protected virtual void Dispose(bool disposing)
StatusMessage = null;
TitleChanged = null;

browser = null;

if (managedCefBrowserAdapter != null)
{
managedCefBrowserAdapter.Dispose();
managedCefBrowserAdapter = null;
}

// Release reference to handlers, make sure this is done after we dispose managedCefBrowserAdapter
// otherwise the ILifeSpanHandler.DoClose will not be invoked. (More important in the WinForms version,
// we do it here for consistency)
Expand Down
24 changes: 12 additions & 12 deletions CefSharp.WinForms/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,31 +485,31 @@ private void InternalDispose(bool disposing)
{
IsBrowserInitialized = false;

// Don't maintain a reference to event listeners anylonger:
AddressChanged = null;
ConsoleMessage = null;
FrameLoadEnd = null;
FrameLoadStart = null;
IsBrowserInitializedChanged = null;
LoadError = null;
LoadingStateChanged = null;
StatusMessage = null;
TitleChanged = null;

browser = null;

if (parentFormMessageInterceptor != null)
{
parentFormMessageInterceptor.Dispose();
parentFormMessageInterceptor = null;
}

if (managedCefBrowserAdapter != null)
{
managedCefBrowserAdapter.Dispose();
managedCefBrowserAdapter = null;
}

// Don't maintain a reference to event listeners anylonger:
AddressChanged = null;
ConsoleMessage = null;
FrameLoadEnd = null;
FrameLoadStart = null;
IsBrowserInitializedChanged = null;
LoadError = null;
LoadingStateChanged = null;
StatusMessage = null;
TitleChanged = null;

// Release reference to handlers, make sure this is done after we dispose managedCefBrowserAdapter
// otherwise the ILifeSpanHandler.DoClose will not be invoked.
this.SetHandlersToNull();
Expand Down
39 changes: 20 additions & 19 deletions CefSharp.Wpf/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,25 @@ private void InternalDispose(bool disposing)
{
if (disposing)
{
Interlocked.Exchange(ref browserInitialized, 0);

UiThreadRunAsync(() =>
{
SetCurrentValue(IsBrowserInitializedProperty, false);
WebBrowser = null;
});

// No longer reference event listeners:
ConsoleMessage = null;
FrameLoadEnd = null;
FrameLoadStart = null;
IsBrowserInitializedChanged = null;
LoadError = null;
LoadingStateChanged = null;
Paint = null;
StatusMessage = null;
TitleChanged = null;

browser = null;

// Incase we accidentally have a reference to the CEF drag data
Expand All @@ -599,7 +618,7 @@ private void InternalDispose(bool disposing)
currentDragData.Dispose();
currentDragData = null;
}

PresentationSource.RemoveSourceChangedHandler(this, PresentationSourceChangedHandler);
// Release window event listeners if PresentationSourceChangedHandler event wasn't
// fired before Dispose
Expand Down Expand Up @@ -642,24 +661,6 @@ private void InternalDispose(bool disposing)
managedCefBrowserAdapter = null;
}

Interlocked.Exchange(ref browserInitialized, 0);
UiThreadRunAsync(() =>
{
SetCurrentValue(IsBrowserInitializedProperty, false);
WebBrowser = null;
});

// No longer reference event listeners:
ConsoleMessage = null;
FrameLoadEnd = null;
FrameLoadStart = null;
IsBrowserInitializedChanged = null;
LoadError = null;
LoadingStateChanged = null;
Paint = null;
StatusMessage = null;
TitleChanged = null;

// Release reference to handlers, make sure this is done after we dispose managedCefBrowserAdapter
// otherwise the ILifeSpanHandler.DoClose will not be invoked. (More important in the WinForms version,
// we do it here for consistency)
Expand Down