2

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.

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.

When I look into the strings stored I find duplicated strings like SQL queries used in SqlDataSource.SelectCommand

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:

<asp:SqlDataSource DataSourceMode="DataSet" CacheDuration="100" ID="myDataSource"
    runat="server" ProviderName="System.Data.Odbc" ConnectionString="<%$ ConnectionStrings:mysql %>"></asp:SqlDataSource>

In the control's Page_Load I have:

myDataSource.SelectCommand =
            "SELECT * from table limit 0,10";

The same string I can find duplicated in memory hundreds of times (probably each time the page is accessed).

Am I missing something? Do I have to dispose the data source manually?

thanks

UPDATE:

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"

After setting EnableViewState="false" for these controls (I did not need it) and the strings are not longer filling up the memory

UPDATE 1:

After setting EnableViewState="false" in production the application pool no longer hits the virtual memory limitation, so PROBLEM SOLVED!

coding-dude.com
  • 526
  • 5
  • 18
  • I suggest you include detailed `Page_Load` event code, since it sounds like `SqlDataSource` fetches data from ODBC source every time the page (re)loads (i.e. including postbacks). – Tetsuya Yamamoto Apr 16 '18 at 06:17
  • Do you interfere with the page cycle somewhere? If not, do you open any other database connections? – Aristos Apr 16 '18 at 06:52
  • that is the whole Page_Load, but I think I was on the wrong track with finding the memory leak - see my update – coding-dude.com Apr 16 '18 at 17:09
  • 1
    It has been well documented by debugging experts like Tess, https://blogs.msdn.microsoft.com/tess/2008/09/09/asp-net-memory-identifying-pages-with-high-viewstate/ So now you can post your own answer and accept it. – Lex Li Apr 19 '18 at 18:20

1 Answers1

1

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"

After setting EnableViewState="false" for these controls (I did not need it) and the strings are not longer filling up the memory

UPDATE 1:

After setting EnableViewState="false" in production the application pool no longer hits the virtual memory limitation, so PROBLEM SOLVED!

This article goes in-depth explaining what's going on: https://blogs.msdn.microsoft.com/tess/2008/09/09/asp-net-memory-identifying-pages-with-high-viewstate/ (thanks Lex Li)

coding-dude.com
  • 526
  • 5
  • 18