473,396 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Life cycle of a COM object in C#-is Release() called?

I have a C# application that uses a C++ COM exe server, and I've
noticed some strange behaviour with the life cycle of the object. In
my .net app, I create an instance of the COM object (generated RCW),
and am able to deal with methods and connection points without any real
problems. The object is a member variable of the main client form.
When the client application is closed however, the COM server is not
always advised, meaning that the exe server process is not ended. I
was able to rectify this by adding a call to Marshal.ReleaseComObject()
to my code, but now I'm wondering what the issue was in the first
place.

My guess at this point is that for COM objects, the Release() method of
the IUnknown interface is called when the object is deleted by the
garbage collector. For some reason, when my client application exits,
the garbage collector isn't always run on its memory, meaning that the
call to Release() never happens. Is this anywhere even close to
correct? Is there something else that I'm missing? At this point I'm
just trying to understand what's happening rather than just guessing,
and I'm sure someone else here has run into a similar issue.

Thanks!

Chris

Nov 17 '05 #1
2 1930
You have to release the COM object by calling
Marshal.ReleaseComObject(object comObject);

<cm******@engmail.uwaterloo.ca> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
I have a C# application that uses a C++ COM exe server, and I've
noticed some strange behaviour with the life cycle of the object. In
my .net app, I create an instance of the COM object (generated RCW),
and am able to deal with methods and connection points without any real
problems. The object is a member variable of the main client form.
When the client application is closed however, the COM server is not
always advised, meaning that the exe server process is not ended. I
was able to rectify this by adding a call to Marshal.ReleaseComObject()
to my code, but now I'm wondering what the issue was in the first
place.

My guess at this point is that for COM objects, the Release() method of
the IUnknown interface is called when the object is deleted by the
garbage collector. For some reason, when my client application exits,
the garbage collector isn't always run on its memory, meaning that the
call to Release() never happens. Is this anywhere even close to
correct? Is there something else that I'm missing? At this point I'm
just trying to understand what's happening rather than just guessing,
and I'm sure someone else here has run into a similar issue.

Thanks!

Chris

Nov 17 '05 #2

Lebesque is correct...

AND the best way to deterministically release the COM object is to implement
an IDisposable pattern on the class that uses the com object. If you
implement IDisposable and use the com containing class in a "using" block
then your COM server will get released when you exit the using block - no
matter how you exit it; aka by completing all steps or by throwing an
exception...

"Lebesgue" wrote:
You have to release the COM object by calling
Marshal.ReleaseComObject(object comObject);

<cm******@engmail.uwaterloo.ca> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
I have a C# application that uses a C++ COM exe server, and I've
noticed some strange behaviour with the life cycle of the object. In
my .net app, I create an instance of the COM object (generated RCW),
and am able to deal with methods and connection points without any real
problems. The object is a member variable of the main client form.
When the client application is closed however, the COM server is not
always advised, meaning that the exe server process is not ended. I
was able to rectify this by adding a call to Marshal.ReleaseComObject()
to my code, but now I'm wondering what the issue was in the first
place.

My guess at this point is that for COM objects, the Release() method of
the IUnknown interface is called when the object is deleted by the
garbage collector. For some reason, when my client application exits,
the garbage collector isn't always run on its memory, meaning that the
call to Release() never happens. Is this anywhere even close to
correct? Is there something else that I'm missing? At this point I'm
just trying to understand what's happening rather than just guessing,
and I'm sure someone else here has run into a similar issue.

Thanks!

Chris


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jim | last post by:
Hi All, I like to know the life cycle of an ASP .NET Application( incudieng server application, such as .NET Web Service). That means from initialization to fully running and how to reboot it or...
2
by: prem | last post by:
Hi, Iam new to ASP.NET. Any one can please give full description about ASP.Net life cycle. Thanks in Advance, Prem.
3
by: | last post by:
Hi all, when are code render blocks rendered in asp.net page life cycle? what method does the code render block rendering? thanks! ingo
6
by: Ilia Chipitsine | last post by:
Dear Sirs, I want to dump all databases, but separately each database in its own file, not all databases in one single file as pg_dumpall does. How can I implement that ? Cheers, Ilia...
16
by: bharathi.vempati | last post by:
hi Can any one explain me the life cycle of C from source code to process termination. please make it fast k bye -ramya
0
by: AC [MVP MCMS] | last post by:
Looking for a configmation here.. In early ASP.NET 2.0 documentation such as the life cycle diagram by Leon Andrianarivony from...
2
by: clintonG | last post by:
I'm having problems referencing public properties in a MasterPage from a class located in App_Code. I need to learn more about the page life cycle and when the classes in App_Code are accessible to...
3
by: aaryan | last post by:
hi all, just want to know the life cycle of an asp.net page with relevant example for each stage. i find many web sites demonstrating them but i feel they are too complex to follow. so can anybody...
1
by: madhu7sudan | last post by:
plz can any one explain abt the complete life cycle of SD. how it work in real time. I mean which stages are crucial.
2
by: =?Utf-8?B?R2FyeSBMYXJpbWVy?= | last post by:
I an asp.net web page with a simple form and a Submit button. Form entries are validated client side, but as a back up I would also like to validate server side, but not sure where to do it code....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.