all groups > dotnet component services > may 2007 >
You're in the

dotnet component services

group:

.NET CLR 1.1 does not release the COM object reference.


.NET CLR 1.1 does not release the COM object reference. johnxhc NO[at]SPAM gmail.com
5/15/2007 6:51:26 PM
dotnet component services:
We have a project in .NET 1.1 , some of the .NET methods take COM
interface reference pointer as a parameter, somehow we have to call
Marshal.ReleaseComObject to release the COM Object, otherwise the COM
object will never get release, Even we call gc.Collect()

But the same code compiles in .NET 2.0 works without the
Marshal.ReleaseComObject. (Unfortunately the project is supposed to
run on .NET 1.1.)


Is this a known problem? What is the remedy besides
Marshal.ReleaseComObject? (We know it is dangerous to call
Marshal.ReleaseComObject since we do not have total control of the
COM
interface pointer )


Thanks in advance.
John
Re: .NET CLR 1.1 does not release the COM object reference. Nicholas Paldino [.NET/C# MVP]
5/15/2007 10:03:16 PM
John,

Regardless of version, you should be calling ReleaseComObject on
references to COM objects that you have when you are done with them. COM
depends on reference counting, and while garbage collection will ultimately
take care of stray references that you have (and properly decrement the
reference count, which will ultimately handle the disposing of the COM
object that the Runtime Callable Wrapper holds on to), it isn't a good idea
to not release the objects when you are done with them.

In other words, don't remove the call in .NET 2.0 because you think it
works.

As for .NET 1.1, the ReleaseComObject method existed on the Marshal
class in that version of the framework, so there is no reason you can't use
it there.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com


[quoted text, click to view]
AddThis Social Bookmark Button