ASP.NET网站中的内存泄漏 [英] Memory leak in ASP.NET web site

查看:93
本文介绍了ASP.NET网站中的内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在重新发布这个因为我真的需要一些建议。


我有一个网页应用程序,可以在每个页面上对数据库进行多次查询。在

为了节省开发工作量,我已经在一个静态类中整合了所有数据库查询到

方法,所以每当我需要数据时,我都会传递一个SQL

一个方法的字符串,我传递了一个datareader或者其他个别值

(字符串,整数等)。


那里在这个应用程序中是一个可怕的内存泄漏。只需一页加载

就会导致大约50 MB的丢失。如果只有在网页响应完成后只恢复内存

,我就可以生活,因为我只需要为服务器添加另外512 MB的RAM并且不会超过两个

或三个用户同时点击该网站(可能会有更多用户同时在
,但在页面加载时间范围内从来没有超过两个

或三个)。我正在观看任务管理器报告内存使用量从一个用户会话中的250左右一直到800MB左右暴涨

,并且它永远不会在SQL之前恢复到
重新启动服务器和IIS服务。 SQL服务器需要大约1/3的过多内存丢失,而IIS占据了b / b
过多内存丢失的大约2/3。


以下是我为解决这个问题所做的工作。


1.创建数据读取器以检索个人的所有通用函数

它们的值现在强制关闭datareader(但不一定是连接的
)。


2.所有数据库连接和数据引用都存储在ArrayList中>
存储在Session中的对象。 (危险,我知道!...但是请

关注我。)


3.所有利用这些数据库功能的网页都继承自
CommonPage类。我在CommonPage中创建了一个解构函数,通过

会话中的连接和datareader ArrayLists中的所有对象创建了
,*关闭它们并将它们从ArrayLists中删除。


4.AppUser存储在Session对象中的对象是使用

缓存创建的,这样从数据库中检索的数据将保留在内存中,以加快页面加载速度。缓存现在在CurrentPage

解构器中被销毁。


5.垃圾收集器在解构器中执行。


应用程序集合中没有存储任何内容。


上述最终结果是在开发机器上节省了大量内存(约20美元)虽然我不确定,但是在服务器上几乎没有任何改变。开发机器正在运行XP专业版和服务器是2003年的b $ b。无论如何,一个人仍然无法通过整个

网站(基于网络的调查)没有崩溃服务器。


我已经把头发拉了一两个星期,想弄清楚这个烂摊子的原因是什么。这对我来说非常重要。


请帮忙,任何人!


Jon

解决方案

在你的page_load函数中,在它的末尾折腾它...


GC.Collect()


它被称为垃圾收集器(好名字。)


" Jon Davis" < jo*@REMOVE.ME.accentra.net>在消息中写道

新闻:eW ************** @ TK2MSFTNGP12.phx.gbl ...

我正在重新发布这是因为我真的需要一些建议。

我有一个Web应用程序,可以在每个页面上对数据库进行许多查询。为了节省开发工作,我已经将所有数据库查询
合并到一个静态类中的方法,所以每当我需要数据时,我都会将一个SQL
字符串传递给一个方法,我传递了一个datareader或其他单独的值
(字符串,整数等)。

此应用程序中存在可怕的内存泄漏。只需一页加载即可导致约50 MB的丢失。如果只要网页响应完成就会恢复
内存,我就可以实现这一点,因为我只是在服务器上添加了另外512 MB的RAM而且从不超过两个<或者三个用户同时点击该网站(可能会有更多用户
同时出现,但在页面加载时间范围内,从不超过两个用户或三个用户)。我正在观看任务管理器报告内存使用量从一个用户会话中的250左右一直到800MB,并且在重新启动SQL Server和IIS服务之前,它是
从未恢复。 SQL服务器占用了大约1/3的过多内存丢失,IIS占据了b
$ b过多的内存丢失。

这就是我所做的试图解决这个问题。

1.创建数据引导程序以从中检索单个值的所有通用函数现在强制关闭数据引导程序(但不一定是连接)。

2.所有数据库连接和数据引用都存储在存储在Session中的ArrayList
对象中。 (危险,我知道!...但是
请关注我。)

3.所有使用这些数据库功能的网页都继承自一个CommonPage类。我在CommonPage中创建了一个解构函数,它通过连接中的所有对象和
中的datareader ArrayLists会话,*关闭它们并将它们从ArrayLists中删除。

4.AppUser。存储在Session对象中的对象已经使用缓存创建了
,以便从数据库中检索的数据将保留在
内存中以加速页面加载。缓存现在在CurrentPage
解构器中被销毁。

5.垃圾收集器在解构器中执行。

Application集合中没有存储任何内容。

以上的最终结果是在开发机器上节省了一些RAM(损失减少了大约20%),但由于某些原因,服务器几乎没有变化,虽然我不确定。开发机器正在运行XP专业版和服务器是2003年。无论如何,一个人仍然无法通过
整个网站(基于网络的调查)而不会崩溃服务器。

我一直把头发拉了一两个星期,试图找出
这个混乱的原因是什么。这对我来说非常重要。

请帮助,任何人!

Jon



< blockquote>见我帖子的第5页。


Jon


" ASP.Confused" <匿名@>在消息中写道

news:e


************** @ TK2MSFTNGP11.phx.gbl ...

在你的page_load函数中,在它的末尾折腾它...

GC.Collect()

它被称为垃圾收集器(好名字。)


Jon Davis < jo*@REMOVE.ME.accentra.net>在消息中写道
新闻:eW ************** @ TK2MSFTNGP12.phx.gbl ...

我正在重新发布这个因为我真的需要一些建议。

我有一个Web应用程序,可以在每个页面上对数据库进行许多查询。
为了节省开发工作,我已经整合了所有数据库
在一个静态类中查询

方法,所以每当我需要数据,我将一个SQL
字符串传递给一个方法,我传递了一个datareader或者个别的


值(字符串,整数等)。

那里在这个应用程序中是一个可怕的内存泄漏。只需一页加载即可导致约50 MB的丢失。如果只有


内存

将在网页响应完成后立即恢复,我可以生活,因为我
刚刚添加了另外512 MB的内存到服务器的RAM并没有超过
两个或三个用户同时点击该网站(同时,

可能会有更多的
用户,但是页面加载时间框架从来没有超过



两个或三个)。我正在观看任务管理器报告内存使用情况
在一个用户会话中从250左右一直暴涨到800MB,它是


从不

恢复,直到重新启动SQL Server和IIS服务。 SQL服务器
占用了大约1/3的过多内存丢失,IIS占用了大约2/3的


过多的内存丢失。 />
以下是我尝试解决此问题的方法。

1.创建数据引导程序以从中检索单个值的所有通用函数现在强制关闭datareader (但不一定是
连接)。

2.所有数据库连接和数据引用都存储在存储在Session中的ArrayList
对象中。 (危险,我知道!...但是


关注我。)

3.所有利用这些数据库功能的网页都继承来自一个CommonPage类。我在CommonPage中创建了一个解构函数,它通过连接中的所有对象和

中的datareader ArrayLists

Session并*关闭*它们并删除它们来自ArrayLists。

4.AppUser存储在Session对象中的对象已经使用

缓存创建


,以便从数据库中检索的数据将保留在


内存中

加快页面加载速度。缓存现在在CurrentPage
解构器中被销毁。

5.垃圾收集器在解构器中执行。

Application集合中没有存储任何内容。

上面的最终结果是在开发机器上节省了大约一半的RAM(损失减少了大约20%),但是服务器上几乎没有任何变化因为
某些原因,虽然我不确定。开发机器运行XP Pro
,服务器是2003.无论如何,一个人仍然无法通过


整个

网站(一个网站)基于调查而不会使服务器崩溃。

我一直在拔头发一两个星期试图找出


什么是

造成这种混乱的原因是。这对我来说非常重要。

请帮忙,任何人!

Jon




I''m reposting this because I really need some advice.

I have a web app that makes many queries to the database on every page. In
order to save development effort, I''ve consolidated all database querying to
methods in a single static class, so whenever I need data, I pass a SQL
string to a method and I am passed a datareader or else individual values
(string, integer, etc).

There is a horrible memory leak in this application. Just one page load
results in a loss of about 50 MB. I COULD LIVE WITH THIS if only the memory
would be restored as soon as the web page response is finished, as I just
added another 512 MB of RAM to the server and there is never more than two
or three users hitting the site at the same time (there may be more users at
the same time, but within page load time frame there''s never more than two
or three). I''m watching the Task Manager report memory usage skyrocketing
from 250 or so all the way up to 800MB in one user session, and it is never
restored until SQL Server and IIS services are restarted. SQL server takes
up about 1/3 of the excessive memory loss, and IIS takes up about 2/3 of the
excessive memory loss.

Here is what I have done to try to resolve this matter.

1. All generic functions that create datareaders to retrieve individual
values from them now forcefully close the datareader (but not necessarily
the connection).

2. All database connections and datareaders are stored into ArrayList
objects which are stored in the Session. (Dangerous, I know! ... but please
follow me.)

3. All web pages that utilize these database functions inherit from a
CommonPage class. I have created a deconstructor in CommonPage that goes
through all the objects in the connections and datareader ArrayLists in the
Session and *closes* them and removes them from the ArrayLists.

4. An "AppUser" object, stored in the Session object, had been created with
a cache so that the data retrieved from the database would remain in memory
to speed up page loads. The cache is now destroyed in the CurrentPage
deconstructor.

5. The garbage collector is executed in the deconstructor.

Nothing is being stored in the Application collection.

The end result of the above is SOME savings of RAM on the development
machine (about 20% less loss), but little no change on the server for some
reason, though I''m not sure. The development machine is running XP Pro and
the server is 2003. In any case, a person still cannot go through the entire
web site (a web-based survey) without crashing the server.

I have been pulling my hair out for a week or two trying to figure out what
the cause of this mess is. This is very important to me.

Please help, anybody!

Jon

解决方案

In your page_load function toss this at the end of it...

GC.Collect()

It''s called a garbage collector (good name.)


"Jon Davis" <jo*@REMOVE.ME.accentra.net> wrote in message
news:eW**************@TK2MSFTNGP12.phx.gbl...

I''m reposting this because I really need some advice.

I have a web app that makes many queries to the database on every page. In
order to save development effort, I''ve consolidated all database querying to methods in a single static class, so whenever I need data, I pass a SQL
string to a method and I am passed a datareader or else individual values
(string, integer, etc).

There is a horrible memory leak in this application. Just one page load
results in a loss of about 50 MB. I COULD LIVE WITH THIS if only the memory would be restored as soon as the web page response is finished, as I just
added another 512 MB of RAM to the server and there is never more than two
or three users hitting the site at the same time (there may be more users at the same time, but within page load time frame there''s never more than two
or three). I''m watching the Task Manager report memory usage skyrocketing
from 250 or so all the way up to 800MB in one user session, and it is never restored until SQL Server and IIS services are restarted. SQL server takes
up about 1/3 of the excessive memory loss, and IIS takes up about 2/3 of the excessive memory loss.

Here is what I have done to try to resolve this matter.

1. All generic functions that create datareaders to retrieve individual
values from them now forcefully close the datareader (but not necessarily
the connection).

2. All database connections and datareaders are stored into ArrayList
objects which are stored in the Session. (Dangerous, I know! ... but please follow me.)

3. All web pages that utilize these database functions inherit from a
CommonPage class. I have created a deconstructor in CommonPage that goes
through all the objects in the connections and datareader ArrayLists in the Session and *closes* them and removes them from the ArrayLists.

4. An "AppUser" object, stored in the Session object, had been created with a cache so that the data retrieved from the database would remain in memory to speed up page loads. The cache is now destroyed in the CurrentPage
deconstructor.

5. The garbage collector is executed in the deconstructor.

Nothing is being stored in the Application collection.

The end result of the above is SOME savings of RAM on the development
machine (about 20% less loss), but little no change on the server for some
reason, though I''m not sure. The development machine is running XP Pro and
the server is 2003. In any case, a person still cannot go through the entire web site (a web-based survey) without crashing the server.

I have been pulling my hair out for a week or two trying to figure out what the cause of this mess is. This is very important to me.

Please help, anybody!

Jon



See #5 of my post.

Jon

"ASP.Confused" <anonymous@> wrote in message
news:e


**************@TK2MSFTNGP11.phx.gbl...

In your page_load function toss this at the end of it...

GC.Collect()

It''s called a garbage collector (good name.)


"Jon Davis" <jo*@REMOVE.ME.accentra.net> wrote in message
news:eW**************@TK2MSFTNGP12.phx.gbl...

I''m reposting this because I really need some advice.

I have a web app that makes many queries to the database on every page. In order to save development effort, I''ve consolidated all database querying

to

methods in a single static class, so whenever I need data, I pass a SQL
string to a method and I am passed a datareader or else individual

values (string, integer, etc).

There is a horrible memory leak in this application. Just one page load
results in a loss of about 50 MB. I COULD LIVE WITH THIS if only the


memory

would be restored as soon as the web page response is finished, as I just added another 512 MB of RAM to the server and there is never more than two or three users hitting the site at the same time (there may be more users at

the same time, but within page load time frame there''s never more than


two or three). I''m watching the Task Manager report memory usage skyrocketing from 250 or so all the way up to 800MB in one user session, and it is


never

restored until SQL Server and IIS services are restarted. SQL server takes up about 1/3 of the excessive memory loss, and IIS takes up about 2/3 of


the

excessive memory loss.

Here is what I have done to try to resolve this matter.

1. All generic functions that create datareaders to retrieve individual
values from them now forcefully close the datareader (but not necessarily the connection).

2. All database connections and datareaders are stored into ArrayList
objects which are stored in the Session. (Dangerous, I know! ... but


please

follow me.)

3. All web pages that utilize these database functions inherit from a
CommonPage class. I have created a deconstructor in CommonPage that goes
through all the objects in the connections and datareader ArrayLists in


the

Session and *closes* them and removes them from the ArrayLists.

4. An "AppUser" object, stored in the Session object, had been created


with

a cache so that the data retrieved from the database would remain in


memory

to speed up page loads. The cache is now destroyed in the CurrentPage
deconstructor.

5. The garbage collector is executed in the deconstructor.

Nothing is being stored in the Application collection.

The end result of the above is SOME savings of RAM on the development
machine (about 20% less loss), but little no change on the server for some reason, though I''m not sure. The development machine is running XP Pro and the server is 2003. In any case, a person still cannot go through the


entire

web site (a web-based survey) without crashing the server.

I have been pulling my hair out for a week or two trying to figure out


what

the cause of this mess is. This is very important to me.

Please help, anybody!

Jon




这篇关于ASP.NET网站中的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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