C# System.String Memory Usage
- From: mwhalber@xxxxxxxxx
- Date: 8 Dec 2006 04:04:52 -0800
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
.
- Follow-Ups:
- Re: C# System.String Memory Usage
- From: John Saunders
- Re: C# System.String Memory Usage
- Prev by Date: Re: C# vs C
- Next by Date: Re: C# System.String Memory Usage
- Previous by thread: RE: threads
- Next by thread: Re: C# System.String Memory Usage
- Index(es):
Relevant Pages
|