473,396 Members | 1,678 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,396 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 10072
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.