473,387 Members | 1,291 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,387 software developers and data experts.

COM Releasing .NET Object

I have an application written in C++ (NOT .NET) which creates an instance of
a vb .net object.

My application releases the .net object when it has finished using it.
However .NET GC is not destroying the object until my application closes
which can be minutes or hours later.

How can my C++ application force the .NET object to be TOTALY destroyed when
I release it.

Thanks.

--
Michael Tissington
http://www.oaklodge.com
http://www.tabtag.com

Nov 21 '05 #1
5 2441
TDC
Is the VB.NET object one you wrote? If it is, then implement a Dispose
method that performs all cleanup explicitly. That way you don't have
to worry about the garbage collector.

Tom

Nov 21 '05 #2
"Michael Tissington" <mi*****@nospam.com> wrote in message
news:eL****************@tk2msftngp13.phx.gbl...
How can my C++ application force the .NET object to be TOTALY destroyed
when I release it.


According to .NET and COM guru Adam Nathan, you should call Dispose from the
COM client in the same way as you would in a .NET app.

If you can't modify the COM client, you can implement a custom marshaler
that calls Dispose when the CCW's ref count reaches zero, but it is complex.

See a post by David Stucki in microsoft.public.dotnet.framework.interop.

Tech blog
http://www.itwriting.com/blog/
Nov 21 '05 #3
I'm writing both the .NET object and the COM client.

So how does the COM client call Dispose on the .NET Object ?

Does the .NET object need to impalement Dispose ?

The problem seems to be related to the COM client using IConnectionPoint to
ask for Events.
Then when the client frees the Connection the .NET object does not release
the client until the .NET object has been really destroyed (at the moment I
have resorted to GC.Collect() to force this).

--
Michael Tissington
http://www.oaklodge.com
http://www.tabtag.com
"Tim Anderson" <ti*****@hotmail.com> wrote in message
news:us**************@TK2MSFTNGP09.phx.gbl...
"Michael Tissington" <mi*****@nospam.com> wrote in message
news:eL****************@tk2msftngp13.phx.gbl...
How can my C++ application force the .NET object to be TOTALY destroyed
when I release it.


According to .NET and COM guru Adam Nathan, you should call Dispose from
the COM client in the same way as you would in a .NET app.

If you can't modify the COM client, you can implement a custom marshaler
that calls Dispose when the CCW's ref count reaches zero, but it is
complex.

See a post by David Stucki in microsoft.public.dotnet.framework.interop.

Tech blog
http://www.itwriting.com/blog/

Nov 21 '05 #4

"Michael Tissington" <mi*****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I'm writing both the .NET object and the COM client.

So how does the COM client call Dispose on the .NET Object ?
Just implement iDisposable in the .NET object. Write code for the Dispose
method that cleans up resources. Then have the COM client call Dispose.

Note this won't actually destroy the object, but it means you can release
resources.
Does the .NET object need to impalement Dispose ?
Yes.
(at the moment I have resorted to GC.Collect() to force this).


Purists will say not to use GC.Collect() but in a situation like this I
wouldn't hesitate if it solves the problem.

Tim
Tech blog
http://www.itwriting.com/blog/
Nov 21 '05 #5
Tim,
| Purists will say not to use GC.Collect() but in a situation like this I
| wouldn't hesitate if it solves the problem.
I would question if it actually solves the problem or simply *masks* the
problem.

By masking the problem I mean making it appear the problem is solved.

I hope you agree that masking the problem is not really the same as solving
the problem. Although masking the problem sometimes is the only "viable"
solution.

For details on when to call GC.Collect see Rule #1 at:
http://blogs.msdn.com/ricom/archive/...29/271829.aspx
http://blogs.msdn.com/ricom/archive/.../02/40780.aspx


Just remember that "the collector is self-tuning so don't mess with it"!

Hope this helps
Jay
"Tim Anderson" <ti*****@hotmail.com> wrote in message
news:eo*************@TK2MSFTNGP11.phx.gbl...
|
| "Michael Tissington" <mi*****@nospam.com> wrote in message
| news:%2****************@TK2MSFTNGP14.phx.gbl...
| > I'm writing both the .NET object and the COM client.
| >
| > So how does the COM client call Dispose on the .NET Object ?
|
| Just implement iDisposable in the .NET object. Write code for the Dispose
| method that cleans up resources. Then have the COM client call Dispose.
|
| Note this won't actually destroy the object, but it means you can release
| resources.
|
| > Does the .NET object need to impalement Dispose ?
|
| Yes.
|
| > (at the moment I have resorted to GC.Collect() to force this).
|
| Purists will say not to use GC.Collect() but in a situation like this I
| wouldn't hesitate if it solves the problem.
|
| Tim
| Tech blog
| http://www.itwriting.com/blog/
|
|
Nov 21 '05 #6

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

Similar topics

4
by: lebo | last post by:
Hi I'm trying to understand how Python handles memory usage and dynamic object loading and unloading. Problem to solve? Build a very low memory footprint (non-GUI) Python application for...
2
by: sausage31 | last post by:
I'm exporting some data to excel but am having trouble getting Access to 'release' Excel. What i want to achieve is to open excel, export some data then leave excel open so that the user can...
18
by: lylefair | last post by:
Can you post code, or a reference to a md? or ad? file on a website, where object variables are not released when they go out of scope and cause a problem, (but causing a problem is extraneous to...
2
by: M.Ob | last post by:
Hello... I am having issues with my asp.net apps not releasing memory. The memory usage for the process w3p.exe continues to grow to it's allowable limit and does not drop until the app pool is...
5
by: Mark Rae | last post by:
Hi, I'm encountering a strange phenomenon whereby a DataSet object is not releasing its memory when it's being disposed and/or set to Nothing. It is part of a Windows service written in VB.NET...
2
by: B.N.Prabhu | last post by:
In my web application(C#) . I am adding one excel sheet and then save and closing that excel file. In the finally bloack i gave Marshal.ReleaseComObject(clsExcel); But when i go and see in the...
12
by: iker.arizmendi | last post by:
Is there any way to get Python to release memory back to the C allocator? I'm currently running a script that goes through the following steps: 1) Creates a very large number of Python objects...
0
by: 062699 | last post by:
Hi All, Thank you in advance. I am having trouble releasing resources when I open a child form. Please see the code below. Form f; private void button1_Click(object sender, EventArgs e) { ...
3
by: ssylee | last post by:
For example, I have a BITMAPINFO* and a BYTE* object to release the resources. Would the most bulletproof way of doing so involve checking to see if they are null, then if they are not, invoke a...
2
by: enggwaqas | last post by:
Hi guys, I have a memory problem in my vb.net application. It's actually a point of sales system, which must be keep running the whole day. The problem is: application is not releasing any memory...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.