我需要使用GC.Collect吗?如果是的话,在哪里? [英] Do I need to use GC.Collect? If yes, where?

查看:84
本文介绍了我需要使用GC.Collect吗?如果是的话,在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在做的事情。


1)用户访问网页并点击按钮构建报告

2)网页访问网页数据类型为DataSet的服务

(公共DataSet methodname()...)
3)Web服务连接到SqlServer,运行BIG报告

4)数据返回给Web服务,Web服务将DataSet返回给web

前端

5)web前端提示用户保存包含以下内容的Excel文件

DataSet数据

#3正在运行时,Web服务器上的aspnet_ws.exe进程增长了很多,比如200美元-500 MB。


问题是服务器似乎在

报告完成后没有释放内存。还有一些报告运行,服务器开始给出了
内存错误。


我见过有人说使用GC.Collect()但我会把它放在哪里?

解决方案

安东尼奥,


不,你不应该叫GC 。收集,^特别是在ASP.NET

环境中。 ASP.NET进入一个很好的小沟(就GC而言,当使用模式一致时,

),你不想惹恼它们

运行你自己的GC'。


你可能得到的错误是由于内存的百分比

ASP.NET是允许在回收过程之前使用。您必须在应用程序的web.config文件中将此值增加到
,以使您的

ASP.NET进程占用更多内存。


如果您的报告返回的数据介于200-500 MB之间,那么您需要重新考虑报告的设计。


另外,任务管理器并不适合监视应用程序的内存消耗。您应该使用性能计数器

来确定正在消耗/释放的内容等等。


最后,^不要^调用GC.Collect,就像在这种情况下一样,它不会为你做任何事情。只要确保你处理所有实现

IDisposable的类型,如果你的报告真的那么大,那么提高网络中允许的内存消耗的价值。配置文件。


希望这会有所帮助。


-

- Nicholas Paldino [.NET / C#MVP ]

- mv*@spam.guard.caspershouse.com

安东尼奥 < BL ***** @ yahoo.com>在消息中写道

news:11 ********************** @ g49g2000cwa.googlegr oups.com ...

您好,我正在做的事情。

1)用户访问网页并点击按钮构建报告
2)网页访问数据类型为DataSet的Web服务
(public DataSet methodname()...)3)web服务连接到SqlServer,运行BIG报告4)数据返回给Web服务,Web服务将DataSet返回给web
前端
5)web前端提示用户保存包含
DataSet数据的Excel文件

#3运行时,aspnet_ws.exe进程就在网络服务器增长很大,比如200-500 MB。

问题是服务器似乎在
报告完成后没有释放内存。还有一些报告运行,服务器开始出现内存错误。

我看到有人说使用GC.Collect()但我会把它放在哪里?


"安东尼奥" < BL ***** @ yahoo.com>在消息中写道

news:11 ********************** @ g49g2000cwa.googlegr oups.com ...

您好,我正在做的事情。

1)用户访问网页并点击按钮构建报告
2)网页访问数据类型为DataSet的Web服务
(public DataSet methodname()...)3)web服务连接到SqlServer,运行BIG报告4)数据返回给Web服务,Web服务将DataSet返回给web
前端
5)web前端提示用户保存包含
DataSet数据的Excel文件

#3运行时,aspnet_ws.exe进程就在网络服务器增长很大,比如200-500 MB。

问题是服务器似乎在
报告完成后没有释放内存。还有一些报告运行,服务器开始出现内存错误。

我看到有人说使用GC.Collect()但我会把它放在哪里?



你可能会在对象上调用Dispose后添加一个GC.Collect。

然而,我想知道这是不是问题?您的200-500 MB数据是否为一组

的非托管Excel对象?如果是这样,你确定你要释放所有

物品吗?


Carl


< blockquote>确定所以不要调用GC.Collect()。我添加了.Dispose到datagrids

和数据集。下载的实际excel文件通常介于5

和25 MB之间。我不确定为什么这个过程会增长200或者更多

MB。您建议我在perfmon中观看什么性能指示器?


谢谢Nicholas


Hello, here is what I am doing.

1) user accesses web page and clicks button to build report
2) web page accesses web service whose data type is DataSet
(public DataSet methodname()...)
3) web service connects to SqlServer, runs BIG report
4) data is returned to web service, web service returns DataSet to web
front-end
5) web front-end prompts user to save Excel file which contains the
DataSet data

While #3 is running, the aspnet_ws.exe process on the web server grows
big, like 200-500 MB.

The problem is the server doesn''t seem to release that memory after the
report is done. A few more report runs and the server starts giving
memory errors.

I have seen people saying use GC.Collect() but where would I put that?

解决方案

Antonio,

No, you shouldn''t be calling GC.Collect, ^especially^ in an ASP.NET
environment. ASP.NET gets into a nice little groove (in terms of GC''s, and
when the pattern of use is consistent) which you don''t want to mess with by
running your own GC''s.

The errors that you are probably getting are due to the % of memory
ASP.NET is allowed to use before the process is recycled. You would have to
up this value in the web.config file for your application, to let your
ASP.NET process take up more memory.

If your report is returning data that is between 200-500 MB, then you
really need to reconsider the design of the report.

Also, Task Manager is not really suitable for monitoring the memory
consumption of an application. You should be using the performance counters
to determine what is being consumed/released, etc, etc.

In the end, ^don''t^ call GC.Collect, as in this case, it isn''t going to
do anything for you. Just make sure you dispose of all types that implement
IDisposable, and if your report is really that big, then raise the value of
the allowed memory consumption in the web.config file.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Antonio" <bl*****@yahoo.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...

Hello, here is what I am doing.

1) user accesses web page and clicks button to build report
2) web page accesses web service whose data type is DataSet
(public DataSet methodname()...)
3) web service connects to SqlServer, runs BIG report
4) data is returned to web service, web service returns DataSet to web
front-end
5) web front-end prompts user to save Excel file which contains the
DataSet data

While #3 is running, the aspnet_ws.exe process on the web server grows
big, like 200-500 MB.

The problem is the server doesn''t seem to release that memory after the
report is done. A few more report runs and the server starts giving
memory errors.

I have seen people saying use GC.Collect() but where would I put that?



"Antonio" <bl*****@yahoo.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...

Hello, here is what I am doing.

1) user accesses web page and clicks button to build report
2) web page accesses web service whose data type is DataSet
(public DataSet methodname()...)
3) web service connects to SqlServer, runs BIG report
4) data is returned to web service, web service returns DataSet to web
front-end
5) web front-end prompts user to save Excel file which contains the
DataSet data

While #3 is running, the aspnet_ws.exe process on the web server grows
big, like 200-500 MB.

The problem is the server doesn''t seem to release that memory after the
report is done. A few more report runs and the server starts giving
memory errors.

I have seen people saying use GC.Collect() but where would I put that?



You would probably add a GC.Collect after you call Dispose on the object.
However, I wonder if that is the problem? Is your 200-500 MB data a group
of unmanaged Excel objects? If so, are you sure you''re releasing ALL of the
objects?

Carl


ok so don''t call GC.Collect(). I have added .Dispose to the datagrids
and datasets. The actual excel file downloaded is usually between 5
and 25 MB. I am not really sure why the process grows by 200 or more
MB. What performance counters would you suggest I watch in perfmon?

thank you Nicholas


这篇关于我需要使用GC.Collect吗?如果是的话,在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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