title: ASP .NET web application memory leaks - profiler shows a lot of strings
body: <p>My web application constantly hits the IIS limitation set on the virtual memory allocated to the application pool. This causes IIS to stop the application.</p>
  
  <p>I've been trying to identify possible memory leaks in my app using .NET memory profiler and so far the largest amount of memory retained after GC seems to be in strings. Even for accessing one page the memory usage grows quite a lot.</p>
  
  <p>When I look into the strings stored I find duplicated strings like SQL queries used in SqlDataSource.SelectCommand</p>
  
  <p>My website consists of a masterpage in which I have some user controls. In one of these user controls I use an SqlDataSource that does a simple select from the database like this:</p>
  
  <pre><code>&lt;asp:SqlDataSource DataSourceMode="DataSet" CacheDuration="100" ID="myDataSource"
      runat="server" ProviderName="System.Data.Odbc" ConnectionString="&lt;%$ ConnectionStrings:mysql %&gt;"&gt;&lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>In the control's Page_Load I have:</p>
  
  <pre><code>myDataSource.SelectCommand =
              "SELECT * from table limit 0,10";
  </code></pre>
  
  <p>The same string I can find duplicated in memory hundreds of times (probably each time the page is accessed).</p>
  
  <p>Am I missing something? Do I have to dispose the data source manually?</p>
  
  <p>thanks</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Turns out that a huge amount of strings (including the SQL queries) were kept in memory because I had a several custom user controls which apparently use by default EnableViewState="true"</p>
  
  <p>After setting EnableViewState="false" for these controls (I did not need it) and the strings are not longer filling up the memory</p>
  
  <p><strong>UPDATE 1:</strong></p>
  
  <p>After setting EnableViewState="false" in production the application pool no longer hits the virtual memory limitation, so PROBLEM SOLVED!</p>