From 967389e246cc8ac901f5ebf52337dd4756a42551 Mon Sep 17 00:00:00 2001 From: dahall Date: Mon, 1 Feb 2021 16:08:43 -0700 Subject: [PATCH] Removed all calls to `Marshal.ReleaseComObject` where there exists a possibility that the interface could have been referenced by another object and changed to nulling the holding variable. See discussion thread #188. --- BITS/BackgroundCopyJob.cs | 1 - Core/InteropServices/ComReleaser.cs | 4 +-- PInvoke/Opc/MsOpc.cs | 3 +- PInvoke/Shell32/ShObjIdl.ShellUtil.cs | 4 +-- System/Network/NetworkConnection.cs | 8 +---- System/Network/NetworkListManager.cs | 2 -- System/Network/NetworkProfile.cs | 2 -- UnitTests/PInvoke/Graphics/DirectWriteTests.cs | 4 +-- Windows.Forms/Components/MRUManager.cs | 30 ++++-------------- Windows.Forms/Controls/ExplorerBrowser.cs | 3 -- .../Controls/ShellNamespaceTreeControl.cs | 7 +---- Windows.Forms/Dialogs/ShellProgressDialog.cs | 1 - Windows.Forms/Extensions/TextBoxExtension.cs | 1 - Windows.Shell/BindContext.cs | 4 +-- Windows.Shell/ControlPanel.cs | 4 +-- Windows.Shell/FileInUseHandler.cs | 1 - .../ShellFileOperationDialog.cs | 1 - .../ShellFileOperations/ShellFileOperations.cs | 6 +--- .../ShellItemPropertyUpdates.cs | 2 -- Windows.Shell/ShellObjects/ComObjWrapper.cs | 1 - Windows.Shell/ShellObjects/ShellContextMenu.cs | 1 - Windows.Shell/ShellObjects/ShellFolder.cs | 2 +- Windows.Shell/ShellObjects/ShellItem.cs | 6 ++-- Windows.Shell/ShellObjects/ShellItemArray.cs | 6 +--- Windows.Shell/ShellObjects/ShellLibrary.cs | 12 ++------ Windows.Shell/ShellObjects/ShellLink.cs | 2 +- .../ShellObjects/ShellSearchConditions.cs | 6 +--- Windows.Shell/ShellObjects/ShellView.cs | 25 +++------------ .../ShellProperties/PropertyDescription.cs | 36 ++++------------------ .../ShellProperties/ReadOnlyPropertyStore.cs | 6 +--- Windows.Shell/TaskBar/TaskbarList.cs | 12 ++------ 31 files changed, 41 insertions(+), 162 deletions(-) diff --git a/BITS/BackgroundCopyJob.cs b/BITS/BackgroundCopyJob.cs index 86444e7a..8415515f 100644 --- a/BITS/BackgroundCopyJob.cs +++ b/BITS/BackgroundCopyJob.cs @@ -716,7 +716,6 @@ namespace Vanara.IO } catch { } Files = null; - Marshal.FinalReleaseComObject(m_ijob); m_ijob = null; m_notifier = null; } diff --git a/Core/InteropServices/ComReleaser.cs b/Core/InteropServices/ComReleaser.cs index 871d2086..4cb13ad1 100644 --- a/Core/InteropServices/ComReleaser.cs +++ b/Core/InteropServices/ComReleaser.cs @@ -14,7 +14,7 @@ namespace Vanara.InteropServices } /// - /// A safe variable to hold an instance of a COM class that automatically calls on disposal. + /// A safe variable to hold an instance of a COM class that automatically releases the instance on disposal. /// /// The type of the COM object. /// @@ -59,8 +59,6 @@ namespace Vanara.InteropServices /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. public void Dispose() { - if (Item == null) return; - Marshal.ReleaseComObject(Item); Item = null; } } diff --git a/PInvoke/Opc/MsOpc.cs b/PInvoke/Opc/MsOpc.cs index 58d5207c..f3fe1ab1 100644 --- a/PInvoke/Opc/MsOpc.cs +++ b/PInvoke/Opc/MsOpc.cs @@ -6856,7 +6856,7 @@ namespace Vanara.PInvoke object IEnumerator.Current => Current; /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - public void Dispose() => Marshal.ReleaseComObject(opcEnum); + public void Dispose() => opcEnum = default; /// Advances the enumerator to the next element of the collection. /// @@ -6874,7 +6874,6 @@ namespace Vanara.PInvoke public void Reset() { var clone = opcEnum.InvokeMethod("Clone"); - Marshal.ReleaseComObject(opcEnum); opcEnum = clone; } } diff --git a/PInvoke/Shell32/ShObjIdl.ShellUtil.cs b/PInvoke/Shell32/ShObjIdl.ShellUtil.cs index b4b6bca2..84cf0971 100644 --- a/PInvoke/Shell32/ShObjIdl.ShellUtil.cs +++ b/PInvoke/Shell32/ShObjIdl.ShellUtil.cs @@ -409,7 +409,7 @@ namespace Vanara.PInvoke private class ManualParentAndItem : IParentAndItem, IDisposable { private readonly PIDL pChild; - private readonly IShellFolder psf; + private IShellFolder psf; public ManualParentAndItem(IShellItem psi) { @@ -421,7 +421,7 @@ namespace Vanara.PInvoke void IDisposable.Dispose() { - Marshal.ReleaseComObject(psf); + psf = null; pChild.Dispose(); } diff --git a/System/Network/NetworkConnection.cs b/System/Network/NetworkConnection.cs index dbae096e..9650e48f 100644 --- a/System/Network/NetworkConnection.cs +++ b/System/Network/NetworkConnection.cs @@ -58,13 +58,7 @@ namespace Vanara.Network /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. void IDisposable.Dispose() { - if (conn == null) return; - if (cost != null) - { - Marshal.FinalReleaseComObject(cost); - cost = null; - } - Marshal.FinalReleaseComObject(conn); + cost = null; conn = null; } } diff --git a/System/Network/NetworkListManager.cs b/System/Network/NetworkListManager.cs index 27f6dc14..ac48b6e4 100644 --- a/System/Network/NetworkListManager.cs +++ b/System/Network/NetworkListManager.cs @@ -166,8 +166,6 @@ namespace Vanara.Network void IDisposable.Dispose() { - if (conns == null) return; - Marshal.FinalReleaseComObject(conns); conns = null; } } diff --git a/System/Network/NetworkProfile.cs b/System/Network/NetworkProfile.cs index 6356ab74..cafa184f 100644 --- a/System/Network/NetworkProfile.cs +++ b/System/Network/NetworkProfile.cs @@ -93,8 +93,6 @@ namespace Vanara.Network /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. void IDisposable.Dispose() { - if (inet == null) return; - Marshal.FinalReleaseComObject(inet); inet = null; } diff --git a/UnitTests/PInvoke/Graphics/DirectWriteTests.cs b/UnitTests/PInvoke/Graphics/DirectWriteTests.cs index d14ed055..059e7c47 100644 --- a/UnitTests/PInvoke/Graphics/DirectWriteTests.cs +++ b/UnitTests/PInvoke/Graphics/DirectWriteTests.cs @@ -116,8 +116,8 @@ namespace Vanara.PInvoke.Tests } finally { - foreach (var i in pList) - Marshal.ReleaseComObject(i); + GC.Collect(); + GC.WaitForPendingFinalizers(); } } diff --git a/Windows.Forms/Components/MRUManager.cs b/Windows.Forms/Components/MRUManager.cs index bf589b94..6186d60a 100644 --- a/Windows.Forms/Components/MRUManager.cs +++ b/Windows.Forms/Components/MRUManager.cs @@ -148,31 +148,13 @@ namespace Vanara.Configuration var type = Type.GetTypeFromProgID("Wscript.Shell"); if (type != null) { - object script = null; - try + var script = Activator.CreateInstance(type); + foreach (var file in Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.Recent), "*.lnk").Where(s => exts.Contains(Path.GetExtension(s.Substring(0, s.Length - 4)).Trim('.').ToLower()))) { - script = Activator.CreateInstance(type); - foreach (var file in Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.Recent), "*.lnk").Where(s => exts.Contains(Path.GetExtension(s.Substring(0, s.Length - 4)).Trim('.').ToLower()))) - { - object sc = null; - try - { - sc = script.InvokeMethod("CreateShortcut", file); - var targetPath = sc.GetPropertyValue("TargetPath"); - if (targetPath != null) - recentFiles.Add(targetPath); - } - finally - { - if (sc != null) - Marshal.FinalReleaseComObject(sc); - } - } - } - finally - { - if (script != null) - Marshal.FinalReleaseComObject(script); + var sc = script.InvokeMethod("CreateShortcut", file); + var targetPath = sc.GetPropertyValue("TargetPath"); + if (targetPath != null) + recentFiles.Add(targetPath); } } } diff --git a/Windows.Forms/Controls/ExplorerBrowser.cs b/Windows.Forms/Controls/ExplorerBrowser.cs index 742d46e7..9f47a76a 100644 --- a/Windows.Forms/Controls/ExplorerBrowser.cs +++ b/Windows.Forms/Controls/ExplorerBrowser.cs @@ -1077,7 +1077,6 @@ namespace Vanara.Windows.Forms explorerBrowserControl.Destroy(); // release com reference to it - Marshal.ReleaseComObject(explorerBrowserControl); explorerBrowserControl = null; } @@ -1554,7 +1553,6 @@ namespace Vanara.Windows.Forms viewDispatch = psv.GetItemObject(SVGIO.SVGIO_BACKGROUND, IID_IDispatch); if (ConnectToConnectionPoint(this, IID_DShellFolderViewEvents, true, viewDispatch, ref viewConnectionPointCookie).Failed) { - Marshal.ReleaseComObject(viewDispatch); viewDispatch = null; } } @@ -1563,7 +1561,6 @@ namespace Vanara.Windows.Forms { if (viewDispatch is null) return; ConnectToConnectionPoint(null, IID_DShellFolderViewEvents, false, viewDispatch, ref viewConnectionPointCookie); - Marshal.ReleaseComObject(viewDispatch); viewDispatch = null; viewConnectionPointCookie = 0; } diff --git a/Windows.Forms/Controls/ShellNamespaceTreeControl.cs b/Windows.Forms/Controls/ShellNamespaceTreeControl.cs index 9dc79108..cb191da4 100644 --- a/Windows.Forms/Controls/ShellNamespaceTreeControl.cs +++ b/Windows.Forms/Controls/ShellNamespaceTreeControl.cs @@ -934,14 +934,9 @@ namespace Vanara.Windows.Forms if (adviseCookie > 0) pCtrl.TreeUnadvise(adviseCookie); SetSite(null); - Marshal.ReleaseComObject(pCtrl); pCtrl = null; } - if (pCtrl2 != null) - { - Marshal.ReleaseComObject(pCtrl2); - pCtrl2 = null; - } + pCtrl2 = null; base.OnHandleDestroyed(e); } diff --git a/Windows.Forms/Dialogs/ShellProgressDialog.cs b/Windows.Forms/Dialogs/ShellProgressDialog.cs index f967e581..874f7226 100644 --- a/Windows.Forms/Dialogs/ShellProgressDialog.cs +++ b/Windows.Forms/Dialogs/ShellProgressDialog.cs @@ -242,7 +242,6 @@ namespace Vanara.Windows.Forms return; if (!closed) Stop(); - Marshal.FinalReleaseComObject(iDlg); iDlg = null; } } diff --git a/Windows.Forms/Extensions/TextBoxExtension.cs b/Windows.Forms/Extensions/TextBoxExtension.cs index 23e2e1fb..58064705 100644 --- a/Windows.Forms/Extensions/TextBoxExtension.cs +++ b/Windows.Forms/Extensions/TextBoxExtension.cs @@ -38,7 +38,6 @@ namespace Vanara.Extensions var ac = new IAutoComplete2(); ac.Init(textBox.Handle, new ComEnumStringImpl(items), null, null); ac.SetOptions(options); - Marshal.ReleaseComObject(ac); } /// Sets the tab stops in a multiline edit control. When text is copied to the control, any tab character in the text causes space to be generated up to the next tab stop. diff --git a/Windows.Shell/BindContext.cs b/Windows.Shell/BindContext.cs index 6b65120d..aaf671bd 100644 --- a/Windows.Shell/BindContext.cs +++ b/Windows.Shell/BindContext.cs @@ -15,7 +15,7 @@ namespace Vanara.Windows.Shell [ComVisible(true)] public class BindContext : IDisposable, IBindCtxV, IBindCtx { - private readonly IBindCtxV iBindCtx; + private IBindCtxV iBindCtx; /// Initializes a new instance of the class. public BindContext() => CreateBindCtx(0, out iBindCtx).ThrowIfFailed(); @@ -130,7 +130,7 @@ namespace Vanara.Windows.Shell } /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - public void Dispose() => Marshal.FinalReleaseComObject(iBindCtx); + public void Dispose() => iBindCtx = null; /// /// Retrieves a pointer to an interface that can be used to enumerate the keys of the bind context's string-keyed table of pointers. diff --git a/Windows.Shell/ControlPanel.cs b/Windows.Shell/ControlPanel.cs index ea1e0b0a..1956bc5a 100644 --- a/Windows.Shell/ControlPanel.cs +++ b/Windows.Shell/ControlPanel.cs @@ -64,7 +64,7 @@ namespace Vanara.Windows.Shell private class SafeCP : IDisposable { - internal readonly IOpenControlPanel icp; + internal IOpenControlPanel icp; private bool disposedValue = false; public SafeCP() => icp = new IOpenControlPanel(); @@ -94,7 +94,7 @@ namespace Vanara.Windows.Shell protected virtual void Dispose(bool disposing) { if (disposedValue) return; - Marshal.ReleaseComObject(icp); + icp = null; disposedValue = true; } } diff --git a/Windows.Shell/FileInUseHandler.cs b/Windows.Shell/FileInUseHandler.cs index 00a65146..99a35711 100644 --- a/Windows.Shell/FileInUseHandler.cs +++ b/Windows.Shell/FileInUseHandler.cs @@ -221,7 +221,6 @@ namespace Vanara.Windows.Shell using var prot = ComReleaserFactory.Create(rot); try { rot.Revoke(regId); } catch { } regId = 0; - Marshal.FinalReleaseComObject(moniker); moniker = null; } } diff --git a/Windows.Shell/ShellFileOperations/ShellFileOperationDialog.cs b/Windows.Shell/ShellFileOperations/ShellFileOperationDialog.cs index c54d69b0..c573226a 100644 --- a/Windows.Shell/ShellFileOperations/ShellFileOperationDialog.cs +++ b/Windows.Shell/ShellFileOperations/ShellFileOperationDialog.cs @@ -306,7 +306,6 @@ namespace Vanara.Windows.Shell iProgressDialog.StopProgressDialog(); Thread.Sleep(500); - Marshal.FinalReleaseComObject(iProgressDialog); iProgressDialog = null; } diff --git a/Windows.Shell/ShellFileOperations/ShellFileOperations.cs b/Windows.Shell/ShellFileOperations/ShellFileOperations.cs index 029c2bff..6ef2d52a 100644 --- a/Windows.Shell/ShellFileOperations/ShellFileOperations.cs +++ b/Windows.Shell/ShellFileOperations/ShellFileOperations.cs @@ -581,11 +581,7 @@ namespace Vanara.Windows.Shell } if (sink != null) op.Unadvise(sinkCookie); - if (op != null) - { - Marshal.FinalReleaseComObject(op); - op = null; - } + op = null; disposedValue = true; } } diff --git a/Windows.Shell/ShellFileOperations/ShellItemPropertyUpdates.cs b/Windows.Shell/ShellFileOperations/ShellItemPropertyUpdates.cs index b2d605dc..2a7c7f7e 100644 --- a/Windows.Shell/ShellFileOperations/ShellItemPropertyUpdates.cs +++ b/Windows.Shell/ShellFileOperations/ShellItemPropertyUpdates.cs @@ -156,8 +156,6 @@ namespace Vanara.Windows.Shell void IDisposable.Dispose() { - if (changes == null) return; - Marshal.FinalReleaseComObject(changes); changes = null; } diff --git a/Windows.Shell/ShellObjects/ComObjWrapper.cs b/Windows.Shell/ShellObjects/ComObjWrapper.cs index 2b2cef11..7a382132 100644 --- a/Windows.Shell/ShellObjects/ComObjWrapper.cs +++ b/Windows.Shell/ShellObjects/ComObjWrapper.cs @@ -29,7 +29,6 @@ namespace Vanara.Windows.Shell /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. public virtual void Dispose() { - Marshal.ReleaseComObject(iObj); iObj = null; } diff --git a/Windows.Shell/ShellObjects/ShellContextMenu.cs b/Windows.Shell/ShellObjects/ShellContextMenu.cs index 69594bc6..427bf452 100644 --- a/Windows.Shell/ShellObjects/ShellContextMenu.cs +++ b/Windows.Shell/ShellObjects/ShellContextMenu.cs @@ -313,7 +313,6 @@ namespace Vanara.Windows.Shell } m_MessageWindow?.Dispose(); - Marshal.ReleaseComObject(ComInterface); ComInterface = null; disposedValue = true; } diff --git a/Windows.Shell/ShellObjects/ShellFolder.cs b/Windows.Shell/ShellObjects/ShellFolder.cs index dbf7eae7..c593b26b 100644 --- a/Windows.Shell/ShellObjects/ShellFolder.cs +++ b/Windows.Shell/ShellObjects/ShellFolder.cs @@ -170,7 +170,7 @@ namespace Vanara.Windows.Shell /// public override void Dispose() { - if (iShellFolder != null) { Marshal.ReleaseComObject(iShellFolder); iShellFolder = null; } + iShellFolder = null; base.Dispose(); } diff --git a/Windows.Shell/ShellObjects/ShellItem.cs b/Windows.Shell/ShellObjects/ShellItem.cs index 69b2a130..f89091c0 100644 --- a/Windows.Shell/ShellObjects/ShellItem.cs +++ b/Windows.Shell/ShellObjects/ShellItem.cs @@ -581,9 +581,9 @@ namespace Vanara.Windows.Shell { if (props != null) { props?.Dispose(); props = null; } if (propDescList != null) { propDescList?.Dispose(); propDescList = null; } - if (qi != null) { Marshal.ReleaseComObject(qi); qi = null; } - if (iShellItem2 != null) { Marshal.ReleaseComObject(iShellItem2); iShellItem2 = null; } - if (iShellItem != null) { Marshal.ReleaseComObject(iShellItem); iShellItem = null; } + qi = null; + iShellItem2 = null; + iShellItem = null; } /// Determines whether the specified , is equal to this instance. diff --git a/Windows.Shell/ShellObjects/ShellItemArray.cs b/Windows.Shell/ShellObjects/ShellItemArray.cs index f0d6d831..2b0f65a9 100644 --- a/Windows.Shell/ShellObjects/ShellItemArray.cs +++ b/Windows.Shell/ShellObjects/ShellItemArray.cs @@ -100,11 +100,7 @@ namespace Vanara.Windows.Shell /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. public virtual void Dispose() { - if (array != null) - { - Marshal.ReleaseComObject(array); - array = null; - } + array = null; } /// Returns an enumerator that iterates through the collection. diff --git a/Windows.Shell/ShellObjects/ShellLibrary.cs b/Windows.Shell/ShellObjects/ShellLibrary.cs index c0361744..ccce5fd6 100644 --- a/Windows.Shell/ShellObjects/ShellLibrary.cs +++ b/Windows.Shell/ShellObjects/ShellLibrary.cs @@ -150,11 +150,7 @@ namespace Vanara.Windows.Shell /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. public override void Dispose() { - if (lib != null) - { - Marshal.ReleaseComObject(lib); - lib = null; - } + lib = null; base.Dispose(); } @@ -221,11 +217,7 @@ namespace Vanara.Windows.Shell /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. public override void Dispose() { - if (lib != null) - { - Marshal.ReleaseComObject(lib); - lib = null; - } + lib = null; base.Dispose(); } diff --git a/Windows.Shell/ShellObjects/ShellLink.cs b/Windows.Shell/ShellObjects/ShellLink.cs index 2bfe913c..704625db 100644 --- a/Windows.Shell/ShellObjects/ShellLink.cs +++ b/Windows.Shell/ShellObjects/ShellLink.cs @@ -290,7 +290,7 @@ namespace Vanara.Windows.Shell /// Dispose the object, releasing the COM ShellLink object public override void Dispose() { - if (link != null) { Marshal.ReleaseComObject(link); link = null; } + link = null; //Release(link); base.Dispose(); } diff --git a/Windows.Shell/ShellObjects/ShellSearchConditions.cs b/Windows.Shell/ShellObjects/ShellSearchConditions.cs index 6c1f105f..22b29ea4 100644 --- a/Windows.Shell/ShellObjects/ShellSearchConditions.cs +++ b/Windows.Shell/ShellObjects/ShellSearchConditions.cs @@ -170,11 +170,7 @@ namespace Vanara.Windows.Shell /// public void Dispose() { - if (condition != null) - { - Marshal.ReleaseComObject(condition); - condition = null; - } + condition = null; } /// Gets the results of the condition by level. diff --git a/Windows.Shell/ShellObjects/ShellView.cs b/Windows.Shell/ShellObjects/ShellView.cs index e1fc5d5d..c8f882ed 100644 --- a/Windows.Shell/ShellObjects/ShellView.cs +++ b/Windows.Shell/ShellObjects/ShellView.cs @@ -335,26 +335,9 @@ namespace Vanara.Windows.Shell User32.DestroyWindow(shellViewWindow); shellViewWindow = HWND.NULL; } - if (iBrowser != null) - { - if (iBrowser.GetType().IsCOMObject) - Marshal.ReleaseComObject(iBrowser); - iBrowser = null; - } - //if (Items != null) - //{ - // Items.Dispose(); - // Items = null; - //} - if (History != null) - { - History = null; - } - if (IShellView != null) - { - Marshal.ReleaseComObject(IShellView); - IShellView = null; - } + iBrowser = null; + History = null; + IShellView = null; } base.Dispose(disposing); } @@ -437,7 +420,7 @@ namespace Vanara.Windows.Shell { prev.UIActivate(SVUIA.SVUIA_DEACTIVATE); prev.DestroyViewWindow(); - Marshal.ReleaseComObject(prev); + prev = null; } IShellView.UIActivate(SVUIA.SVUIA_ACTIVATE_NOFOCUS); diff --git a/Windows.Shell/ShellProperties/PropertyDescription.cs b/Windows.Shell/ShellProperties/PropertyDescription.cs index 91678adb..ba53978f 100644 --- a/Windows.Shell/ShellProperties/PropertyDescription.cs +++ b/Windows.Shell/ShellProperties/PropertyDescription.cs @@ -133,16 +133,8 @@ namespace Vanara.Windows.Shell public virtual void Dispose() { // typeList?.Dispose(); - if (iDesc2 != null) - { - Marshal.ReleaseComObject(iDesc2); - iDesc2 = null; - } - if (iDesc != null) - { - Marshal.ReleaseComObject(iDesc); - iDesc = null; - } + iDesc2 = null; + iDesc = null; } /// Gets a formatted string representation of a property value. @@ -233,11 +225,7 @@ namespace Vanara.Windows.Shell /// public virtual void Dispose() { - if (iList != null) - { - Marshal.ReleaseComObject(iList); - iList = null; - } + iList = null; } /// @@ -354,16 +342,8 @@ namespace Vanara.Windows.Shell /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. public virtual void Dispose() { - if (iType2 != null) - { - Marshal.ReleaseComObject(iType2); - iType2 = null; - } - if (iType != null) - { - Marshal.ReleaseComObject(iType); - iType = null; - } + iType2 = null; + iType = null; } /// Returns a that represents this instance. @@ -399,11 +379,7 @@ namespace Vanara.Windows.Shell /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. public virtual void Dispose() { - if (iList != null) - { - Marshal.ReleaseComObject(iList); - iList = null; - } + iList = null; } /// Determines the index of a specific item in the list. diff --git a/Windows.Shell/ShellProperties/ReadOnlyPropertyStore.cs b/Windows.Shell/ShellProperties/ReadOnlyPropertyStore.cs index 2592fe44..eb2dba6a 100644 --- a/Windows.Shell/ShellProperties/ReadOnlyPropertyStore.cs +++ b/Windows.Shell/ShellProperties/ReadOnlyPropertyStore.cs @@ -92,11 +92,7 @@ namespace Vanara.Windows.Shell /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. public virtual void Dispose() { - if (iPropertyStore != null) - { - Marshal.ReleaseComObject(iPropertyStore); - iPropertyStore = null; - } + iPropertyStore = null; } /// Gets the property. diff --git a/Windows.Shell/TaskBar/TaskbarList.cs b/Windows.Shell/TaskBar/TaskbarList.cs index ca3af12c..941fc72f 100644 --- a/Windows.Shell/TaskBar/TaskbarList.cs +++ b/Windows.Shell/TaskBar/TaskbarList.cs @@ -503,16 +503,8 @@ namespace Vanara.Windows.Shell { ~TaskbarListStaticFinalizer() { - if (taskbar2 != null) - { - Marshal.ReleaseComObject(taskbar2); - taskbar2 = null; - } - if (taskbar4 != null) - { - Marshal.ReleaseComObject(taskbar4); - taskbar4 = null; - } + taskbar2 = null; + taskbar4 = null; } } }