all groups > dotnet performance > may 2006 >
You're in the

dotnet performance

group:

Cleaning up COM Objects



Cleaning up COM Objects Srini
5/22/2006 12:26:48 PM
dotnet performance: If I create several COM objects in a loop but point to the same variable, do
I need to clean up each object or only one at the end. It works both ways
but I am not sure if the first method actually cleans up all resources.
Here is what I mean

private void COMTest()
{
COMObject test;
try
{
for(int i = 0; i < 10; i++)
test = COMApp.GetCOMObject();
}
catch
{}
finally
{ System.Runtime.InteropServices.Marshal.ReleaseComObject(test);
}
}

OR

private void COMTest()
{
COMObject test;
try
{
for(int i = 0; i < 10; i++)
{
test = COMApp.GetCOMObject();
System.Runtime.InteropServices.Marshal.ReleaseComObject(test);
}
}
catch
{}
}

Thanks

Srinivas

Re: Cleaning up COM Objects Phil Wilson
5/22/2006 12:41:35 PM
Duplicated post - see framework.interop, and please don't post multiple
messages like this.
--
Phil Wilson [MVP Windows Installer]
----
[quoted text, click to view]

AddThis Social Bookmark Button