简体   繁体   English

使用RedGate Memory Profiler了解ASP.net中的内存泄漏

[英]Understanding memory leaks in ASP.net using RedGate Memory Profiler

I am running a large ASP.net 4.0 website. 我正在运行一个大型的ASP.net 4.0网站。 It uses a popular .Net content management system, has thousands of content items, hundreds of concurrent users - is basically a heavy website. 它使用了流行的.Net内容管理系统,拥有数千个内容项,数百个并发用户 - 基本上是一个沉重的网站。

Over the course of 1 day the memory usage of the IIS7 worker process can rise to 8-10GB. 在1天的过程中,IIS7工作进程的内存使用量可以增加到8-10GB。 The server has 16GB installed and is currently set to recycle the app pool once per day. 服务器已安装16GB,目前设置为每天回收一次应用程序池。

I am getting pressured to reduce memory usage. 我受到压力以减少内存使用量。 Much of the memory usage is due to caching of large strings of data - but the cache interval is only set to 5-10 minutes - so these strings should eventually expire from memory. 大部分内存使用是由于缓存大量数据 - 但缓存间隔仅设置为5-10分钟 - 因此这些字符串最终应该从内存到期。

However after running RedGate Memory Profiler I can see what I think are memory leaks. 但是在运行RedGate Memory Profiler之后,我可以看到我认为的内存泄漏。 I have filtered my Instance List results by objects that are "kept in memory exclusively by Disposed Objects" ( I read on the RedGate forum that this is how you find memory leaks ). 我已经通过“由Disposed Objects专门保存在内存中”的对象过滤了我的实例列表结果(我在RedGate论坛上看到这是你发现内存泄漏的方式)。 This gave me a long list of strings that are being held in memory. 这给了我一长串的内存字符串。

For each string I use Instance Retention Graph to see what holds it in memory. 对于每个字符串,我使用实例保留图来查看内存中保存它的内容。 The System.string objects seem to have been cached at some point by System.Web.Caching.CacheDependency. System.string对象似乎在某些时候被System.Web.Caching.CacheDependency缓存了。 If I follow the graph all the way up it goes through various other classes including System.Collections.Specialized.ListDictionary until it reaches System.Web.FileMonitor. 如果我一直遵循图形,它会通过各种其他类,包括System.Collections.Specialized.ListDictionary,直到它到达System.Web.FileMonitor。 This makes some sense as the strings are paths to a file (images / PDFs / etc). 这是有道理的,因为字符串是文件的路径(图像/ PDF /等)。

It seems that the CMS is caching paths to files, but these cached objects are then "leaked". 似乎CMS正在缓存文件的路径,但这些缓存的对象随后被“泄露”。 Over time this builds up and eats up RAM. 随着时间的推移,这会增加并消耗RAM。

Sorry this is long winded... Is there a way for me to stop these memory leaks? 对不起,这是啰嗦......有没有办法阻止这些内存泄漏? Or to clear them down without resorting to recycling the app pool? 或者在不诉诸回收应用程序池的情况下清除它们? Can I find what class / code is doing the caching to see if I can fix the leak? 我可以找到正在进行缓存的类/代码,看看我是否可以修复泄漏?

It sounds like the very common problem of stuff being left in memory as part of session state. 这听起来像是作为会话状态的一部分留在内存中的东西的常见问题。 If that's the case your only options are 1. don't put so much stuff in each user's session, 2. Set the session lifetime to something shorter (the default is 20 minutes, I think), and 3. periodically recycle the app pool. 如果是这种情况,你唯一的选择是1.不要在每个用户的会话中放置太多东西,2。将会话生命周期设置为更短的时间(默认为20分钟,我认为),并且3.定期回收应用程序池。

As part of 1. I found that there are "good ways" and "bad ways" of presenting data in a data grid control. 作为1的一部分,我发现在数据网格控件中呈现数据有“好方法”和“坏方法”。 You may want to check that you are copying only the data you need and not accidentally maintaining references to the entire datagrid. 您可能希望检查是否只复制了所需的数据,而不是意外地维护对整个数据网格的引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM