From 66a734e53fc9bf33b0c9ccae2c130caa72fed3b6 Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Tue, 27 Feb 2024 16:51:03 -0500 Subject: [PATCH] Dispose memory stream while updating icons (#14967) * comments * comments --- src/DynamoCoreWpf/PublicAPI.Unshipped.txt | 39 ++++++++++++++++++- src/DynamoCoreWpf/UI/Converters.cs | 17 +++++--- .../Views/Debug/UpdateNodeIconsWindow.xaml.cs | 10 ++--- 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/DynamoCoreWpf/PublicAPI.Unshipped.txt b/src/DynamoCoreWpf/PublicAPI.Unshipped.txt index 6011c374305..a58f458aab6 100644 --- a/src/DynamoCoreWpf/PublicAPI.Unshipped.txt +++ b/src/DynamoCoreWpf/PublicAPI.Unshipped.txt @@ -1,4 +1,4 @@ -abstract Dynamo.PackageManager.UI.PackageItemViewModel.Items.get -> System.Collections.ObjectModel.ObservableCollection +abstract Dynamo.PackageManager.UI.PackageItemViewModel.Items.get -> System.Collections.ObjectModel.ObservableCollection abstract Dynamo.PackageManager.UI.PackageItemViewModel.Items.set -> void abstract Dynamo.Wpf.Extensions.ViewExtensionBase.Dispose() -> void abstract Dynamo.Wpf.Extensions.ViewExtensionBase.Name.get -> string @@ -37,6 +37,10 @@ Dynamo.Controls.AutoLacingToVisibilityConverter Dynamo.Controls.AutoLacingToVisibilityConverter.AutoLacingToVisibilityConverter() -> void Dynamo.Controls.AutoLacingToVisibilityConverter.Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object Dynamo.Controls.AutoLacingToVisibilityConverter.ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object +Dynamo.Controls.Base64ToImageConverter +Dynamo.Controls.Base64ToImageConverter.Base64ToImageConverter() -> void +Dynamo.Controls.Base64ToImageConverter.Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object +Dynamo.Controls.Base64ToImageConverter.ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object Dynamo.Controls.BinaryRadioButtonCheckedConverter Dynamo.Controls.BinaryRadioButtonCheckedConverter.BinaryRadioButtonCheckedConverter() -> void Dynamo.Controls.BinaryRadioButtonCheckedConverter.Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object @@ -3970,6 +3974,36 @@ Dynamo.Wpf.Views.CodeHighlightingRuleFactory Dynamo.Wpf.Views.Debug.DebugModesWindow Dynamo.Wpf.Views.Debug.DebugModesWindow.DebugModesWindow() -> void Dynamo.Wpf.Views.Debug.DebugModesWindow.InitializeComponent() -> void +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.InitializeComponent() -> void +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.IsUpdateEnabled.get -> bool +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.IsUpdateEnabled.set -> void +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.NewIconPaths.get -> string +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.NewIconPaths.set -> void +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.NodeIconMetadata +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.NodeIconMetadata.IconName.get -> string +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.NodeIconMetadata.IconName.set -> void +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.NodeIconMetadata.IconResxFile.get -> string +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.NodeIconMetadata.IconResxFile.set -> void +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.NodeIconMetadata.IconSuffix.get -> string +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.NodeIconMetadata.IconSuffix.set -> void +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.NodeIconMetadata.Icon_Base64String.get -> string +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.NodeIconMetadata.Icon_Base64String.set -> void +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.NodeIconMetadata.IsUpdated.get -> bool +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.NodeIconMetadata.IsUpdated.set -> void +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.NodeIconMetadata.NewIconPath.get -> string +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.NodeIconMetadata.NewIconPath.set -> void +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.NodeIconMetadata.NodeIconMetadata(string nodeName, string newIconPath, string iconName, string iconSuffix, string oldData, string resxFile, bool isUpdated = false) -> void +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.NodeIconMetadata.NodeName.get -> string +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.NodeIconMetadata.NodeName.set -> void +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.NodeIconMetadata.OldData.get -> string +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.NodeIconMetadata.OldData.set -> void +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.Output.get -> string +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.Output.set -> void +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.PropertyChanged -> System.ComponentModel.PropertyChangedEventHandler +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.UpdatedIconList.get -> System.Collections.ObjectModel.ObservableCollection +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.UpdatedIconList.set -> void +Dynamo.Wpf.Views.Debug.UpdateNodeIconsWindow.UpdateNodeIconsWindow(System.Collections.Generic.IEnumerable entries) -> void Dynamo.Wpf.Views.FileTrust.FileTrustWarning Dynamo.Wpf.Views.FileTrust.FileTrustWarning.FileTrustWarning(Dynamo.Controls.DynamoView dynamoViewWindow) -> void Dynamo.Wpf.Views.FileTrust.FileTrustWarning.InitializeComponent() -> void @@ -5350,6 +5384,7 @@ static Dynamo.Wpf.Properties.Resources.UnloadFailureMessageBoxTitle.get -> strin static Dynamo.Wpf.Properties.Resources.UnpinNodeTooltip.get -> string static Dynamo.Wpf.Properties.Resources.UnsavedChangesMessageBoxTitle.get -> string static Dynamo.Wpf.Properties.Resources.UpdateMessage.get -> string +static Dynamo.Wpf.Properties.Resources.UpdateNodeIconsDebugMenu.get -> string static Dynamo.Wpf.Properties.Resources.UsageReportPromptDialogTitle.get -> string static Dynamo.Wpf.Properties.Resources.UseLevelKeepListStructureHint.get -> string static Dynamo.Wpf.Properties.Resources.UseLevelKeepListStructurePopupMenuItem.get -> string @@ -5594,4 +5629,4 @@ virtual Dynamo.Wpf.ViewModels.Watch3D.DefaultWatch3DViewModel.UpdateHelpers() -> virtual Dynamo.Wpf.ViewModels.Watch3D.DefaultWatch3DViewModel.ZoomToFit(object parameter) -> void virtual Dynamo.Wpf.ViewModels.Watch3D.HelixWatch3DViewModel.OnWatchExecution() -> void virtual Dynamo.Wpf.ViewModels.Watch3D.HelixWatch3DViewModel.UpdateUpstream() -> void -virtual UI.Prompts.PortPropertiesEditPrompt.OnPropertyChanged(System.ComponentModel.PropertyChangedEventArgs e) -> void \ No newline at end of file +virtual UI.Prompts.PortPropertiesEditPrompt.OnPropertyChanged(System.ComponentModel.PropertyChangedEventArgs e) -> void diff --git a/src/DynamoCoreWpf/UI/Converters.cs b/src/DynamoCoreWpf/UI/Converters.cs index a46f10dbdcf..62303a59fd0 100644 --- a/src/DynamoCoreWpf/UI/Converters.cs +++ b/src/DynamoCoreWpf/UI/Converters.cs @@ -3386,13 +3386,18 @@ public object Convert(object value, Type targetType, object parameter, System.Gl if (string.IsNullOrEmpty(s)) return null; - BitmapImage bi = new BitmapImage(); - - bi.BeginInit(); - bi.StreamSource = new MemoryStream(System.Convert.FromBase64String(s)); - bi.EndInit(); + BitmapImage loadedBitM = null; + using (MemoryStream ms = new MemoryStream(System.Convert.FromBase64String(s))) + { + BitmapImage bi = new BitmapImage(); + bi.BeginInit(); + bi.StreamSource = ms; + bi.CacheOption = BitmapCacheOption.OnLoad; + bi.EndInit(); + loadedBitM = bi; + } - return bi; + return loadedBitM; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) diff --git a/src/DynamoCoreWpf/Views/Debug/UpdateNodeIconsWindow.xaml.cs b/src/DynamoCoreWpf/Views/Debug/UpdateNodeIconsWindow.xaml.cs index 0d7096bda4d..6cd4892f8a6 100644 --- a/src/DynamoCoreWpf/Views/Debug/UpdateNodeIconsWindow.xaml.cs +++ b/src/DynamoCoreWpf/Views/Debug/UpdateNodeIconsWindow.xaml.cs @@ -14,21 +14,21 @@ namespace Dynamo.Wpf.Views.Debug { /// - /// Interaction logic for DebugModesWindow.xaml + /// Interaction logic for UpdateNodeIconsWindow.xaml /// public partial class UpdateNodeIconsWindow : Window, INotifyPropertyChanged { #region properties //The path that will be used to store log files related to this process - public static readonly string logPath = Path.Combine(Directory.GetCurrentDirectory(), @"NodeIconUpdateLog"); - public string errorFile = Path.Combine(logPath, @"error_icons.csv"); - public string logFile = Path.Combine(logPath, @"success_icons.csv"); + private static readonly string logPath = Path.Combine(Directory.GetCurrentDirectory(), @"NodeIconUpdateLog"); + private string errorFile = Path.Combine(logPath, @"error_icons.csv"); + private string logFile = Path.Combine(logPath, @"success_icons.csv"); IEnumerable entries; public event PropertyChangedEventHandler PropertyChanged; - protected void OnPropertyChanged(string propertyName) + internal void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); }