0

When use WinDbg to trace memory usage issue, I found there are million strings which occupy 100+MBs totally. Our application is a financial type APP, so there are ten thousands accounts and each account has many string type properties.

My question is: is there any good articles/resource about tuning memory issue, especial for the string type? Thanks in advance.

2 Answers 2

1

You probably need to look at your design.Having Millions of strings is probably not a good idea/design.

Although not sure what exactly your design is,you can tune your strings using

  • StringBuilder
  • String interning

With a normal string object ,every modification on the string creates a new string object and this can bring unnecessary memory pressure.You can alleviate this problem using the stringbuilder class.The StringBuilder object maintains a internal character array and any modifications doesnt create a new string object,rather the internal character array is modified.The string is obtained by calling the ToString() on the StringBuilder object.

More here

http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.aspx

String interning is a process where you place unique strings on a common pool and is shared across applications.This reduces the need to create a string if it is already created and interned in the pool.

More here

http://msdn.microsoft.com/en-us/library/system.string.intern.aspx

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer. I have a question about the string intern. If I even don't know which string is used frequently and duplicate, how can i use this tec to improve the memory usage?
0

StringBuilder might be the way to go. You need to split the string. You need large memory and StringBuilder You have to do this directly I think.

2 Comments

I know StringBuilder. I don't think it is a problem here, since directly operate string only effect the performance (more temp garbage), but never cause memory leak, doesn't it?
Look at the memory usage. Use extensive debugging. It is probably your design. Is there a lot of references everywhere in the code. Are there static class variables, links and references to objects everywhere. The garbage collector will collect unreferenced and unused strings/objects that is not being used. It is your application design I think. I think it is designed to cache strings or the design is at fault.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.