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