views:

136

answers:

2

Hi,

For a web application developed on ASP.NET, we are finding that for user control files (ascx) we are returning long strings as a result of method calls. These are embedded in the ascx pages using the special tags <% %>

When performing memory dump analysis for the application, we find that many of those strings are not being garbage collected. Also, the ascx pages are compiled to temporary DLLs and they are held in memory. Is this responsible for causing the long strings to remain in memory and not be garbage collected ?

Note : The strings are larger than 85K in size.

+1  A: 

If they are being generated as string literals then likely they are being interned. An interned string is unlikely to be released during the lifetime of the application. This would explain why the variable is not being collected.

You can verify this by tagging the assembly with the CompilationRelaxations attribute and the flag NoStringInterning.

The Intern property on System.String has a good bit of information on this subject under the Performance section

JaredPar
The String in this case is a call to toString() on an object
Icarus
+1  A: 

Your strings are allocated on the large object heap, which are not collected with other small objects. It uses a different threshold, as explained by Tess Ferrandez. As she advises, you can try calling

GC.Collect(3)
GC.WaitForPendingFinalizers()
GC.Collect(3)

and see if they are being collected.

plodoc