Insane System.String Memory usage

Z

Zach Tong

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 small/short.

It seems like the System.String objects are not getting released. Any
idea why? Any tips to reduce the memory usage? Thanks.
 
J

Jay B. Harlow [MVP - Outlook]

Zach,
It seems like the System.String objects are not getting released. Any
idea why? Any tips to reduce the memory usage? Thanks.
It really depends on how & what you are doing with the strings. Without
seeing your code, or a small sampling of your typical code, I'm not sure any
one here can really answer your question.
From what I
understand, the StringBuilder only helps with speed increases (by
reducing time to create a new string).
It reduces the time by avoiding creating a new string altogether, Remember
if you avoid creating a new string, then you reduce the memory that
System.String uses. It really depends on how & why you are creating new
strings if StringBuilder will help or not.

Hope this helps
Jay
 
W

Willy Denoyette [MVP]

They aren't released as long as you hold a reference to it. Without seeing
any code it's hard to tell why references are held.
I suggest you post a complete sample that illustrate your findings.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top