System.String to be disposed or not

Use this forum to discuss subjects that don't belong in the other forums.
Post Reply
Posts: 9
Joined: Thu Jun 04, 2015 8:44 pm

System.String to be disposed or not

Post by bhargava381 » Tue Jun 09, 2015 10:26 pm

Hi ,
I have been trying to dispose the strings .I was not sucessfull in doing so they are being introduced from RuntimePropertyInfo , Pinned GC Handle () and my 3rd party contol's which are poining to string.
In this below artcile from MSDN, it states to worry less about any string and array objects less than 85,000 bytes that is LOH.

( ... mory.aspx)

So my question now is , should we only worry about object greater than 85,000 bytes.If so, can we force the LOH to clear.As far as I know,Gen # 2 clean up triggers LOH to clean.


Andreas Suurkuusk
Posts: 1030
Joined: Wed Mar 02, 2005 7:53 pm

Re: System.String to be disposed or not

Post by Andreas Suurkuusk » Thu Jun 11, 2015 7:26 am

Strings and arrays may very well be part of a memory leak. but, as it says in the article, string and arrays are used by almost all parts of the .NET Framework and a .NET program. Therefore it is recommended that you focus on other types which can more easily be identified as potential memory leaks. If you for instance have a document type, and you have a new document instance after you open and close the document, then it's probably easier to focus on that single new instances than on maybe thousands of new string instances used by the document.

Instead of looking at string and array types, you can use Held bytes column in the Types list to identify types which use a lot of memory. If you have a document instance that are using a lot of strings, the held bytes value for the document type will include the size of all those string, even if there is only a single instance of the document. For more information about held bytes, see ... tances.htm.
Best regards,

Andreas Suurkuusk
SciTech Software AB

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 6 guests