Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix splash screen mem leaks - cherry pick to master #14364

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 12 additions & 2 deletions src/DynamoCoreWpf/Views/SplashScreen/SplashScreen.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public DynamoView DynamoView
set
{
dynamoView = value;
if(dynamoView == null)
{
return;
}
viewModel = value.DataContext as DynamoViewModel;
// When view model is closed, we need to close the splash screen if it is displayed.
viewModel.RequestClose += SplashScreenRequestClose;
Expand Down Expand Up @@ -484,8 +488,14 @@ internal void CloseWindow()
// RequestUpdateLoadBarStatus event needs to be unsubscribed when the splash screen window is closed, to avoid populating the info on splash screen.
else
{
this.Close();
viewModel?.Model.ShutDown(false);
Close();
if (viewModel != null)
{
viewModel.RequestClose -= SplashScreenRequestClose;
}

DynamoView?.Close();
DynamoView = null;
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/GraphMetadataViewExtension/GraphMetadataViewExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ public override void Closed()

protected virtual void Dispose(bool disposing)
{
viewModel.Dispose();

this.graphMetadataMenuItem.Checked -= MenuItemCheckHandler;
this.graphMetadataMenuItem.Unchecked -= MenuItemUnCheckedHandler;
viewModel?.Dispose();
if (graphMetadataMenuItem != null)
{
graphMetadataMenuItem.Checked -= MenuItemCheckHandler;
graphMetadataMenuItem.Unchecked -= MenuItemUnCheckedHandler;
}
}

public override void Dispose()
Expand Down
16 changes: 12 additions & 4 deletions src/LintingViewExtension/LintingViewExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,18 @@ public override void Shutdown()

public override void Dispose()
{
this.linterMenuItem.Checked -= MenuItemCheckHandler;
this.linterMenuItem.Unchecked -= MenuItemUnCheckedHandler;
if (linterManager != null) linterManager.PropertyChanged -= OnLinterManagerPropertyChange;
viewLoadedParamsReference.ViewExtensionOpenRequest -= OnViewExtensionOpenRequest;
if (linterMenuItem != null)
{
linterMenuItem.Checked -= MenuItemCheckHandler;
linterMenuItem.Unchecked -= MenuItemUnCheckedHandler;
}
if (linterManager != null){
linterManager.PropertyChanged -= OnLinterManagerPropertyChange;
}
if (viewLoadedParamsReference != null)
{
viewLoadedParamsReference.ViewExtensionOpenRequest -= OnViewExtensionOpenRequest;
}
}

public override void Closed()
Expand Down
25 changes: 17 additions & 8 deletions src/Notifications/NotificationsViewExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ObservableCollection<Logging.NotificationMessage> Notifications
get { return notifications; }
private set
{
if(notifications != value)
if (notifications != value)
notifications = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Notifications)));
}
Expand Down Expand Up @@ -62,17 +62,26 @@ public void Dispose()
{
UnregisterEventHandlers();
//for some reason the menuItem was not being gc'd in tests without manually removing it
viewLoadedParams.dynamoMenu.Items.Remove(notificationsMenuItem.MenuItem);
BindingOperations.ClearAllBindings(notificationsMenuItem.CountLabel);
viewLoadedParams?.dynamoMenu.Items.Remove(notificationsMenuItem.MenuItem);
if (notificationsMenuItem != null)
{
BindingOperations.ClearAllBindings(notificationsMenuItem.CountLabel);
}
notificationsMenuItem = null;
disposed = true;
}
}

private void UnregisterEventHandlers()
{
viewLoadedParams.NotificationRecieved -= notificationHandler;
Notifications.CollectionChanged -= notificationsMenuItem.NotificationsChangeHandler;
if (viewLoadedParams != null)
{
viewLoadedParams.NotificationRecieved -= notificationHandler;
}
if (notificationsMenuItem != null)
{
Notifications.CollectionChanged -= notificationsMenuItem.NotificationsChangeHandler;
}
}

public void Loaded(ViewLoadedParams viewStartupParams)
Expand All @@ -83,7 +92,7 @@ public void Loaded(ViewLoadedParams viewStartupParams)
logger = viewModel.Model.Logger;

Notifications = new ObservableCollection<Logging.NotificationMessage>();

notificationHandler = (notificationMessage) =>
{
Notifications.Add(notificationMessage);
Expand Down Expand Up @@ -117,12 +126,12 @@ internal void AddNotifications()

public void Shutdown()
{
// Do nothing for now
// Do nothing for now
}

public void Startup(ViewStartupParams viewStartupParams)
{
// Do nothing for now
// Do nothing for now
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ private void DataContext_Closed(object sender, EventArgs e)
public override void Dispose()
{
PackageDetailsViewModel?.Dispose();
ViewLoadedParamsReference.ViewExtensionOpenRequestWithParameter -= OnViewExtensionOpenWithParameterRequest;
if (ViewLoadedParamsReference != null)
{
ViewLoadedParamsReference.ViewExtensionOpenRequestWithParameter -= OnViewExtensionOpenWithParameterRequest;
}
}

public override void Closed()
Expand Down
15 changes: 11 additions & 4 deletions src/PythonMigrationViewExtension/PythonMigrationViewExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,17 @@ private void UnSubscribeWorkspaceEvents()

private void UnsubscribeEvents()
{
LoadedParams.CurrentWorkspaceChanged -= OnCurrentWorkspaceChanged;
DynamoViewModel.CurrentSpaceViewModel.Model.NodeAdded -= OnNodeAdded;
DynamoViewModel.Model.Logger.NotificationLogged -= OnNotificationLogged;
CurrentWorkspace.RequestPackageDependencies -= PythonDependencies.AddPythonPackageDependency;
if (LoadedParams != null)
{
LoadedParams.CurrentWorkspaceChanged -= OnCurrentWorkspaceChanged;
DynamoViewModel.CurrentSpaceViewModel.Model.NodeAdded -= OnNodeAdded;
DynamoViewModel.Model.Logger.NotificationLogged -= OnNotificationLogged;
}

if (CurrentWorkspace != null)
{
CurrentWorkspace.RequestPackageDependencies -= PythonDependencies.AddPythonPackageDependency;
}
UnSubscribeWorkspaceEvents();
}
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public override string UniqueId
/// </summary>
public override void Dispose()
{
DependencyView.Dispose();
DependencyView?.Dispose();
dataRows = null;
localDefinitionDataRows = null;
externalFilesDataRows = null;
Expand Down