473,396 Members | 1,968 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.

System.String Memory Usage

Hi,

I have created a service which parses real-time prices from one format
into another. This is all working very quickly and nicely, however, I
have recently found that the memory usage is astronomical after a few
hours. (1.5-2 Gig)

After a good amount of digging I found that the memory usage is is all
in System.String and contained within the pricing object. This object
makes extensive use of a single string object which is passed as an OUT
parameter to a Interop (unmanaged) object.

There are approximately 30 calls to the unmanaged interop object within
the class, and the class is called upwards of 3-4 times per second. I
know that System.Strings are immutable, therefore, I am assuming that
each time this call returns within the class, a new String object is
being created and allocated. The issue is that many of these objects
are being promoted to Gen2 and never being finalized/destroyed by the
GC. The GC apparently assumes that all these string objects are still
alive and will not remove them. I think that this is due to the
frequency at which these objects are being created.

Unfortunately I cannot mitigate the impact using StringBuilder, as the
parameters are OUT string on the interop assembly (this could be
changed by my colleague who wrote it, if neccesary.)

Anyway, does anyone have any idea how to get the memory usage down to a
manageable level?

Kind Regards,
Mike

Dec 11 '06 #1
2 2358
Are you talking about web service here? Breakdown and show you code if
possible. At the mean time I can only say do check for the redundant loop
and so.

chanmm

"miguel" <mw******@gmail.comwrote in message
news:11**********************@80g2000cwy.googlegro ups.com...
Hi,

I have created a service which parses real-time prices from one format
into another. This is all working very quickly and nicely, however, I
have recently found that the memory usage is astronomical after a few
hours. (1.5-2 Gig)

After a good amount of digging I found that the memory usage is is all
in System.String and contained within the pricing object. This object
makes extensive use of a single string object which is passed as an OUT
parameter to a Interop (unmanaged) object.

There are approximately 30 calls to the unmanaged interop object within
the class, and the class is called upwards of 3-4 times per second. I
know that System.Strings are immutable, therefore, I am assuming that
each time this call returns within the class, a new String object is
being created and allocated. The issue is that many of these objects
are being promoted to Gen2 and never being finalized/destroyed by the
GC. The GC apparently assumes that all these string objects are still
alive and will not remove them. I think that this is due to the
frequency at which these objects are being created.

Unfortunately I cannot mitigate the impact using StringBuilder, as the
parameters are OUT string on the interop assembly (this could be
changed by my colleague who wrote it, if neccesary.)

Anyway, does anyone have any idea how to get the memory usage down to a
manageable level?

Kind Regards,
Mike
Dec 12 '06 #2
Futher, check also for anything you are doing that might be putting the
string(s) into (for instance) a static container, either directly or
indirectly. As an example, if you have a class that subscribes to a
static event, then because the static delegate can now see your class,
and because static fields are not eligible for collection, thus your
class will never be collected unless you detach the event. Likewise
collections, hashtables, properties, etc.

If your code has an instance that stays alive for a long time (e.g.
visible somewhere under Main() for an app), then the same can also be
true.

A third cause: do you have any async methods that you do not finish
correctly? With delegates you *must* call EndInvoke sooner or later (to
confuse matters, Control.EndInvoke does not suffer this, but I don't
think that this applies here).

Marc

Dec 12 '06 #3

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

Similar topics

5
by: Justice | last post by:
Currently I'm doing some experimenting with the XMLHTTP object in Javascript. Now, the XMLHttp object is asynchronous (at least in this case), and the following code causes a significant memory...
2
by: tomvr | last post by:
Hello I have noticed some 'weird' memory usage in a vb.net windows app The situation is as follows I have an app (heavy on images) with 2 forms (actually there are more forms and on starting...
2
by: Zach Tong | last post by:
I recently ran our code through a profiler to determine why it was using so much memory. It turns out the System.String object is taking 95% of the memory. We have considered converting the...
2
by: Tony | last post by:
tHi, I have application with memory leaks and I used .Net memory profiler. It showed that every time I use string, gc does not clear that string and at the end I have many instances and bytes...
9
by: Niels Dekker - no reply address | last post by:
Are all the following initializations semantically equivalent? wchar_t a = {L'\0'}; wchar_t b = {'\0'}; wchar_t c = {0}; wchar_t d = {}; If so, why don't we all use an empty initializer...
7
by: Malcolm | last post by:
This is a program to convert a text file to a C string. It is offered as a service to the comp.lang.c community. Originally I thought it would be a five minute job to program. In fact there are...
41
by: Baron Samedi | last post by:
I want to produce a piece of software for embedded systems, generally telecoms based, mostly running on ARM processors, but I can't guarantee that, of course. My software should work along with...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
1
by: Jean-Paul Calderone | last post by:
On Tue, 22 Apr 2008 14:54:37 -0700 (PDT), yzghan@gmail.com wrote: The test doesn't demonstrate any leaks. It does demonstrate that memory usage can remain at or near peak memory usage even after...
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
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
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.