EnumeratorViewOfEnumVariant implements an interface called
ICustomAdapter, which has a method called GetUnderlyingObject.  So if
you use IEnumerator explicitly (rather than doing foreach) you can do
the following:

IEnumerator enumerator = comObj.GetEnumerator();
try
{
  while (enumerator.MoveNext()) { ... }
}
finally
{
  ICustomAdapter adapter = (ICustomAdapter)enumerator;
  Marshal.ReleaseComObject(adapter.GetUnderlyingObject());
}

Adam

-----Original Message-----
From: Rune Huseby [mailto:[EMAIL PROTECTED]] 
Sent: Friday, April 19, 2002 10:41 AM
To: [EMAIL PROTECTED]
Subject: [DOTNET] COM interop and explicit Release of IEnumXXXX

I need to explicitly Release some COM-objects that hold on
to some precious resources. Unfortunately these objects 
doesn't provide a Close method.

I have found Marshall.ReleaseComObject(), that will 
release the object for most RCW-objects. 

The bad news is that ReleaseComObject() will not work 
on the IEnumerator-interface that is wrapped around 
IEnumXXXX. It appears the the RCW IEnumerator is implemented
by EnumeratorViewOfEnumVariant, that in turn holds 
a reference to the IEnumXXX in its private m_pEnumVariantObj
member. And since EnumeratorViewOfEnumVariant inaccessible to
my code, I have dangling resources.

Setting all my references to null and calling GC.Collect();
does not seem to help either.



The COM-library I am using is Visual SourceSafe Automation, 
and the troublesome COM-object is VSSVersions, which there can be
only one instance of.

-- 
Rune Huseby

You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to