ASP .NET Web应用程序内存泄漏-分析器显示了很多字符串 [英] ASP .NET web application memory leaks - profiler shows a lot of strings

查看:64
本文介绍了ASP .NET Web应用程序内存泄漏-分析器显示了很多字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Web应用程序不断达到分配给应用程序池的虚拟内存上的IIS限制设置.这将导致IIS停止应用程序.

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.

我一直在尝试使用.NET内存探查器识别应用程序中可能的内存泄漏,到目前为止,在GC之后保留的最大内存量似乎是字符串.即使访问一页,内存使用量也会增长很多.

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.

当我查看存储的字符串时,我发现重复的字符串,例如SqlDataSource.SelectCommand中使用的SQL查询

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

我的网站由一个母版页组成,其中包含一些用户控件.在这些用户控件之一中,我使用了SqlDataSource,它可以从数据库中进行如下简单选择:

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>

在控件的Page_Load中,我有:

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?

谢谢

更新:

事实证明,由于我有几个自定义用户控件,这些字符串(包括SQL查询)被保留在内存中,这些控件显然在默认情况下使用EnableViewState ="true"

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"

为这些控件设置EnableViewState ="false"(我不需要它)之后,字符串不再占用内存

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

更新1:

在生产环境中设置EnableViewState ="false"后,应用程序池不再达到虚拟内存限制,因此问题已解决!

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

推荐答案

事实证明,内存中保留了大量字符串(包括SQL查询),因为我有几个自定义用户控件,这些控件显然默认使用EnableViewState =真实"

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"

为这些控件设置EnableViewState ="false"(我不需要它)之后,字符串不再占用内存

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

更新1:

在生产环境中设置EnableViewState ="false"后,应用程序池不再达到虚拟内存限制,因此问题已解决!

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

本文深入介绍了发生的情况: https://blogs.msdn.microsoft.com/tess/2008/09/09/asp-net-memory-identifying-pages-with-high-viewstate/(感谢Lex Li)

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)

这篇关于ASP .NET Web应用程序内存泄漏-分析器显示了很多字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆