473,625 Members | 3,210 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2381
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.goog legroups.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.EndInvo ke 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
6069
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 loss even though I seem to be allocaitng everything; help would be *vastly* appreciated. What am I doing wrong here? I thought I was doing everything correctly (setting things to null, for example) but none of the memory seems to get replaced. ...
2
460
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 the app I load some things into memory for global use of the app but I'll use only 2 starting forms to explain the situation) situation 1 start app with form 1 (72mb memory usage), show form 2 and hide form 1 (89 mb memory usage
2
460
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 strings to StringBuilder objects, but I don't think this will help. From what I understand, the StringBuilder only helps with speed increases (by reducing time to create a new string). In addition to that, most of the string manipulations are very...
2
10117
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 allocated for strings. Is there a right way to use strings? Or StringBuilder is the answer? THanks
9
27048
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 list, {}, when zero-initializing a C-style string? I was wondering, because the book C++ Coding Standards (Sutter & Alexandrescu) says at item 19, "Always
7
2604
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 subtle problems, such as the fact that a text file may wrap lines. It will be appearing on my website as soon as I get update access, assuming no one finds anything wrong with it. /*
41
381
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 other software which will generally be written in C or C++ (occasionally in ADA or even assembler). I suppose that there are C compilers for marginally more processors than C++, but, realistically, I am not sure that it makes a major difference.
232
13240
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 set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an integer, without any junk thrown in, i.e. it must satisfy the regular expression: ^ *?+ *$ If the...
1
2033
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 the objects for which that memory was allocated are no longer live in the process. This is only a leak if peak memory goes up again each time you create any new objects. Try repeated allocations of a large dictionary and observe how memory...
0
8259
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8192
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8696
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8358
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5571
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2621
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1504
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.