473,323 Members | 1,622 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,323 software developers and data experts.

System.String memory leaks C# application.

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
Jul 21 '05 #1
2 10057
hi
Put simply, a string type is immutable and a StringBuilder is NOT.

Immutable means that after created it cannot be modfied, changed, etc. -
This is what a string type is, if you add even just one character to a string
using either the + or &

myString = myString & "HI"

A new string is created (an additional OBJECT is created)

A StringBuilder is NOT immutable (Mutable), so you can add, remove, modify,
etc. a StringBuilder object and new objects will NOT be created. So, if you
need to dynamically construct a string or manipulate one always use a
StringBuilder object.

C# Example:

StringBuilder sb = new StringBuilder("You can pass in a string to the
contstructor");
sb.Append(" and then add some more");

regards
Ansil
Dimensions
Technopark TVM
an****@gmail.com

"Tony" wrote:
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

Jul 21 '05 #2
Hi Tony,

It's not really a memory leak as much as it is memory usage. The gc will
eventually pick up all the strings. You don't control the logic of the gc.

As the other responder mentioned, using StringBuilder will make many string
operations far more efficient.

--- Nick

"Tony" <To**@discussions.microsoft.com> wrote in message
news:83**********************************@microsof t.com...
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

Jul 21 '05 #3

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

Similar topics

1
by: Sergey Tursanov | last post by:
Hello all ! When I use code below and check my program with various memory leak detection tools I get message about memory leaks in stl_alloc.h. #include <string> int main() { std::string s...
0
by: Steve Binney | last post by:
My code makes synchronous HttpWebRequest and HttpRebResponse calls. In VS 2003, I am getting memory leaks and event handle leaks. I am closing all streams and using "using"statements. I have...
4
by: Morten Aune Lyrstad | last post by:
Ok, now I'm officially confused. I have a large project going, which uses a win32 ui library I am developing myself. And I'm getting weird memory leaks. I don't know if I can explain what is going...
12
by: Andla Rand | last post by:
Hi, I almost feel like giving up on developing on dotnet. I have done several threaded programs with the goal to parse webpages and I have tried WebClient and then WinSock. Both programs has...
0
by: Frank Lopez | last post by:
Does anyone know if Microsoft generated a whitepaper on this topic? Does anyone know what the solution is? (meaning, eliminate the leak problem -- I am seeing three memory leaks from...
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...
22
by: Michael Rasmussen | last post by:
Hi all, Not sure if this is OT? I have a function in a library written in C++ which returns a strdup(s.c_str()) to an application written i C. Running Valgrind on my C-application shows this...
2
by: asterixgallier | last post by:
Hello i'm having problems with log4cxx when using inside an MFC application build with visual studio 2005. The Application starts and works normaly, but while exiting, inside the DEBUG window of...
8
by: BillE | last post by:
I have an existing asp.net 2.0 webforms app using master/content pages, and it works fine. I added some Ajax elements, including some UpdatePanels and modal PopUp panels which contain asp.net...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.