473,325 Members | 2,771 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,325 software developers and data experts.

garbage collection in C# and .NET

Hi All,

I am having a terrible problem with the garbage collector of the .NET
run-time.

My mangaged code(c#) application sends a System.String object to an unmanged
world COM client function
The COM client is exposed to my C# application by wrapping it in a class
with _gc keyword(e.g public _gc class DotNetWrapper).

In the Wrapper, the function returns a String*, which is nothing but a BSTR
returned from the COM client.

So ultimately in my C# application i have a pointer to a String object.
And as i send and receive response in a loop, garbage collection does not
seem to be happening and my
machine just takes more than 300MB and then hangs.

If i explicitly call System.gc.Collect(), even then memory cleanup is done
only randomly and not immediately.

If i write a C++ client to access my COM object, i can do a ::SysFreeString
on the BSTR to immediately free the memory.
Could anyone suggest a solution for this.

Thanks
Vinu


Nov 17 '05 #1
1 1294
vinu,

Why are you creating a managed wrapper for your pre-existing COM class?
If anything, you should use COM interop to handle the access to this, and
let the runtime handle marshalling the string to your client correctly (as
well as the disposal).

Hope this helps.

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

"vinu" <vi*****@yahoo.com> wrote in message
news:eP****************@TK2MSFTNGP15.phx.gbl...
Hi All,

I am having a terrible problem with the garbage collector of the .NET
run-time.

My mangaged code(c#) application sends a System.String object to an
unmanged
world COM client function
The COM client is exposed to my C# application by wrapping it in a class
with _gc keyword(e.g public _gc class DotNetWrapper).

In the Wrapper, the function returns a String*, which is nothing but a
BSTR
returned from the COM client.

So ultimately in my C# application i have a pointer to a String object.
And as i send and receive response in a loop, garbage collection does not
seem to be happening and my
machine just takes more than 300MB and then hangs.

If i explicitly call System.gc.Collect(), even then memory cleanup is done
only randomly and not immediately.

If i write a C++ client to access my COM object, i can do a
::SysFreeString
on the BSTR to immediately free the memory.
Could anyone suggest a solution for this.

Thanks
Vinu

Nov 17 '05 #2

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

Similar topics

1
by: Bob | last post by:
Are there any known applications out there used to test the performance of the .NET garbage collector over a long period of time? Basically I need an application that creates objects, uses them, and...
6
by: Ganesh | last post by:
Is there a utility by microsoft (or anyone) to force garbage collection in a process without have access to the process code. regards Ganesh
11
by: Rick | last post by:
Hi, My question is.. if Lisp, a 40 year old language supports garbage collection, why didn't the authors of C++ choose garbage collection for this language? Are there fundamental reasons behind...
34
by: Ville Voipio | last post by:
I would need to make some high-reliability software running on Linux in an embedded system. Performance (or lack of it) is not an issue, reliability is. The piece of software is rather simple,...
5
by: Bob lazarchik | last post by:
Hello: We are considering developing a time critical system in C#. Our tool used in Semiconductor production and we need to be able to take meaurements at precise 10.0 ms intervals( 1000...
8
by: mike2036 | last post by:
For some reason it appears that garbage collection is releasing an object that I'm still using. The object is declared in a module and instantiated within a class that is in turn instantiated by...
28
by: Goalie_Ca | last post by:
I have been reading (or at least googling) about the potential addition of optional garbage collection to C++0x. There are numerous myths and whatnot with very little detailed information. Will...
56
by: Johnny E. Jensen | last post by:
Hellow I'am not sure what to think about the Garbage Collector. I have a Class OutlookObject, It have two private variables. Private Microsoft.Office.Interop.Outlook.Application _Application =...
350
by: Lloyd Bonafide | last post by:
I followed a link to James Kanze's web site in another thread and was surprised to read this comment by a link to a GC: "I can't imagine writing C++ without it" How many of you c.l.c++'ers use...
158
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.