hey all.
i am allocating an object using
Activator.CreateInstance(System.Type);
I get a reference to the Com object.
however, i am not sure how to close down the object that i have.
do i need to call Marshal.ReleaseComObject()?
will the garbage collector collect it without me calling it
ReleaseComObject?
what about all the interfaces that i 'cast' out of the Com object?
do i need to call ReleaseComObject for each one of them?
what about calling ReleaseComObject in general,
do i need to call it in order to release the object immediately,
meaning, if i do not call ReleaseComObject, than the garbage collector will
do it for me?
what about Com interfaces that are pointing to each other,
in an intricate mesh?
like a linked list?
do i need to release the list each node in an orderly manner?
or simply stop pointing at its head?
meaning, if i stop pointing at the head, will the entire linked list be
released?
what about hardware resources held by a Com interface,
do i need to tell the Com interface to release the resource?
or can i simply stop pointing at the Com interface and expect the garbage
collector to release all hardware resources?
please, i know that i am asking a lot,
but i do not know where to read about this.
if anyone has a source of information that i can read this,
i would be greatfull if you point me at it.
thank a lot.
assaf
>do i need to call Marshal.ReleaseComObject()?
If you want to know when the object is realeased, yes.
>will the garbage collector collect it without me calling it
>ReleaseComObject?
Yes, but you don't know exactly when.
>what about all the interfaces that i 'cast' out of the Com object?
>do i need to call ReleaseComObject for each one of them?
No, you call ReleaseComObject once per object (or actually once for
each time the object has been marshaled into managed code).
>what about calling ReleaseComObject in general,
>do i need to call it in order to release the object immediately,
>meaning, if i do not call ReleaseComObject, than the garbage collector will
>do it for me?
Exactly
>meaning, if i stop pointing at the head, will the entire linked list be
>released?
Any objects that you no longer reference will be collected at the next
GC.
>what about hardware resources held by a Com interface,
>do i need to tell the Com interface to release the resource?
The COM object should release any resorces it still holds at the last
Release call, before the object is destroyed.
>but i do not know where to read about this.
http://blogs.gotdotnet.com/cbrumme/permalink.aspx/940d1191-3cc5-4b8d-a8b3-68b47f
2f8dcb
(The link currently doesn't work here).
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.