<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>ASP.NET Quiz Answers: Does Page.Cache leak memory?</title><link>http://blogs.msdn.com/tess/archive/2006/08/11/asp-net-quiz-answers-does-page-cache-leak-memory.aspx</link><description>A few days ago I posted a question I had gotten on email (look here for complete post): " We use Page.Cache to store temporary data, but we have recently discovered that it causes high memory consumption. The bad thing is that the memory never goes down</description><dc:language>sv-SE</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>ASP.NET Caching</title><link>http://blogs.msdn.com/tess/archive/2006/08/11/asp-net-quiz-answers-does-page-cache-leak-memory.aspx#695336</link><pubDate>Fri, 11 Aug 2006 13:55:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:695336</guid><dc:creator>writerus drivelus</dc:creator><description /></item><item><title>Interesting Finds: August 10 part 2 and August 11, 2006</title><link>http://blogs.msdn.com/tess/archive/2006/08/11/asp-net-quiz-answers-does-page-cache-leak-memory.aspx#696194</link><pubDate>Sat, 12 Aug 2006 06:24:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:696194</guid><dc:creator>Jason Haley</dc:creator><description /></item><item><title>re: ASP.NET Quiz Answers: Does Page.Cache leak memory?</title><link>http://blogs.msdn.com/tess/archive/2006/08/11/asp-net-quiz-answers-does-page-cache-leak-memory.aspx#699490</link><pubDate>Mon, 14 Aug 2006 16:34:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:699490</guid><dc:creator>Blake05</dc:creator><description>Very nice Follow up. Keep em coming.&lt;br&gt;&lt;br&gt;-blake</description></item><item><title>Link Listing - August 14, 2006</title><link>http://blogs.msdn.com/tess/archive/2006/08/11/asp-net-quiz-answers-does-page-cache-leak-memory.aspx#700627</link><pubDate>Tue, 15 Aug 2006 07:45:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:700627</guid><dc:creator>Christopher Steen</dc:creator><description>&lt;br&gt; &amp;nbsp;Announcing &lt;br&gt; &amp;nbsp;the Windows Mobile Virtual User Group Meeting [Via: trobbins ] &lt;br&gt; &amp;nbsp;Refactoring &lt;br&gt;...</description></item><item><title>re: ASP.NET Quiz Answers: Does Page.Cache leak memory?</title><link>http://blogs.msdn.com/tess/archive/2006/08/11/asp-net-quiz-answers-does-page-cache-leak-memory.aspx#739206</link><pubDate>Mon, 04 Sep 2006 13:03:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:739206</guid><dc:creator>JA</dc:creator><description>Excellent. Thanks for this.</description></item><item><title>re: ASP.NET Quiz Answers: Does Page.Cache leak memory?</title><link>http://blogs.msdn.com/tess/archive/2006/08/11/asp-net-quiz-answers-does-page-cache-leak-memory.aspx#866524</link><pubDate>Tue, 24 Oct 2006 04:52:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:866524</guid><dc:creator>Tu Hoang</dc:creator><description>&lt;p&gt;the 2.0 Framework is also facing the same issue.&lt;/p&gt;</description></item><item><title>re: ASP.NET Quiz Answers: Does Page.Cache leak memory?</title><link>http://blogs.msdn.com/tess/archive/2006/08/11/asp-net-quiz-answers-does-page-cache-leak-memory.aspx#871190</link><pubDate>Wed, 25 Oct 2006 08:54:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:871190</guid><dc:creator>Tess</dc:creator><description>&lt;p&gt;Any version of the framework will. &amp;nbsp;It is not really a problem in the framework as such but a problem with hooking up eventhandlers and delegate to static/cache objects.&lt;/p&gt;
</description></item><item><title>ASP.NET Crash: Bad CacheItemRemovedCallback - Part II</title><link>http://blogs.msdn.com/tess/archive/2006/08/11/asp-net-quiz-answers-does-page-cache-leak-memory.aspx#1159164</link><pubDate>Mon, 27 Nov 2006 13:47:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1159164</guid><dc:creator>If broken it is, fix it you should</dc:creator><description>&lt;p&gt;In August I wrote about how you could cause a nasty high memory situation by using CacheItemRemovedCallbacks&lt;/p&gt;
</description></item><item><title>re: ASP.NET Quiz Answers: Does Page.Cache leak memory?</title><link>http://blogs.msdn.com/tess/archive/2006/08/11/asp-net-quiz-answers-does-page-cache-leak-memory.aspx#1787879</link><pubDate>Fri, 02 Mar 2007 17:30:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1787879</guid><dc:creator>dasveed</dc:creator><description>&lt;p&gt;Can you advise what objects are stored in the asp.net &amp;quot;internal cache&amp;quot;. I.e. the performance counter &amp;quot;Cache Total Entries&amp;quot; is a total of the counter &amp;quot;Cache API entries&amp;quot; and some other entries - &amp;quot;internal asp.net&amp;quot; cache entries.&lt;/p&gt;
&lt;p&gt;In our application, we have about 1000 entries in the API cache - some compiled xslt transforms (with 3 hour expiries) and some other smaller stuff, but our &amp;quot;Cache Total Entries&amp;quot; is peaking at about 15000.&lt;/p&gt;
&lt;p&gt;If we turn off &amp;quot;disableMemoryCollection&amp;quot; in machine/web.config then scavenging decides to cull everything in the cache.&lt;/p&gt;
&lt;p&gt;If we turn it on, privatebytes bloats up until it runs out of memory and we have to recycle our web app's worker process.&lt;/p&gt;
&lt;p&gt;It's all pointing to a bug in .net 2's implementation of cache scavenging. &lt;/p&gt;
&lt;p&gt;Any ideas what .net uses the cache for internally?&lt;/p&gt;</description></item><item><title>re: ASP.NET Quiz Answers: Does Page.Cache leak memory?</title><link>http://blogs.msdn.com/tess/archive/2006/08/11/asp-net-quiz-answers-does-page-cache-leak-memory.aspx#8436236</link><pubDate>Tue, 29 Apr 2008 01:38:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8436236</guid><dc:creator>Todd Powers</dc:creator><description>&lt;p&gt;I was having a similar issue and stumbled across your quiz and consequently these answers. &amp;nbsp;The articles and comments were all a great read and I did learn a lot from this. &amp;nbsp;So thank you.&lt;/p&gt;
&lt;p&gt;My issue was that I was storing objects in cache, which, when expired, still consumed memory.&lt;/p&gt;
&lt;p&gt;I was under the assumption that the framework would automatically call the Dispose() method on any object which implemented IDisposable, when the object was expired from cache.&lt;/p&gt;
&lt;p&gt;This seems like a legitimate expectation, doesn't it? &amp;nbsp;Is there some reason why this isn't done?&lt;/p&gt;
&lt;p&gt;I ended up solving my problem by implementing a Shared sub in a global class, and passing AddressOf -sub- into the Cache.Insert, as the onRemove callback function.&lt;/p&gt;
&lt;p&gt;I would have assumed that we didn't have to go to all this trouble, if the object implemented the IDisposable interface. &amp;nbsp;I would have assumed that the framework would have been responsible enough to dispose of the object itself when the object was expired from cache.&lt;/p&gt;
&lt;p&gt;The work-around did the trick, but don't you think the framework should have handled this?&lt;/p&gt;
&lt;p&gt;I'd be interested to know if not, why?&lt;/p&gt;</description></item><item><title>re: ASP.NET Quiz Answers: Does Page.Cache leak memory?</title><link>http://blogs.msdn.com/tess/archive/2006/08/11/asp-net-quiz-answers-does-page-cache-leak-memory.aspx#8436766</link><pubDate>Tue, 29 Apr 2008 11:22:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8436766</guid><dc:creator>Tess</dc:creator><description>&lt;p&gt;I dont have enough information about why it was implemented this way to make any type of judgement on that, and I can see how people might jump to the conclusion that IDisposable objects are disposed/closed when thrown out of cache.&lt;/p&gt;
&lt;p&gt;However, if you think about it from a broader perspective, there really is no difference between an object going out of scope when a method ends, or when it gets thrown out of cache. For example if you use a connection in a method you would have to manually close it or use a using statement to get it auto disposed/closed. &amp;nbsp;If you don't it will stick around until finalized...&lt;/p&gt;
&lt;p&gt;I could see one problem with autodisposing items when they are no longer cached, if for example someone else has a reference to it you would end up with a situation where you would have a reference to an already disposed object, without knowing it... Something like that might be possible to check for, but there is always a tradeoff between perf and getting all the frills.&lt;/p&gt;
&lt;p&gt;Don't get me wrong, I see your point but I think that very careful consideration would have to be taken before making such a decision. Since off the top of my head I can already come up with one issue with it, I personally think the current solution, where the developer is given a choice to do something with the object when it goes out of scope may just be the cleanest one...&lt;/p&gt;
&lt;p&gt;Anyways, just my 2 cent, in reality I don't know enough about the decisions around this to talk intelligently about it. &lt;/p&gt;
</description></item><item><title>ASP.NET Memory Issues - High Memory Usage with AjaxPro (fixed in current version)</title><link>http://blogs.msdn.com/tess/archive/2006/08/11/asp-net-quiz-answers-does-page-cache-leak-memory.aspx#8951733</link><pubDate>Sun, 14 Sep 2008 18:05:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8951733</guid><dc:creator>If broken it is, fix it you should</dc:creator><description>&lt;p&gt;I was helping a colleague out with an OOM (OutOfMemory) situation he was dealing with. Problem description:&lt;/p&gt;
</description></item><item><title>re: ASP.NET Quiz Answers: Does Page.Cache leak memory?</title><link>http://blogs.msdn.com/tess/archive/2006/08/11/asp-net-quiz-answers-does-page-cache-leak-memory.aspx#9890531</link><pubDate>Wed, 02 Sep 2009 22:08:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9890531</guid><dc:creator>Mike</dc:creator><description>&lt;p&gt;Can you please reply to the comment &amp;quot;Friday, March 02, 2007 9:30 AM by dasveed&amp;quot;? &amp;nbsp;I have noticed the same types of numbers in my application.&lt;/p&gt;</description></item><item><title>re: ASP.NET Quiz Answers: Does Page.Cache leak memory?</title><link>http://blogs.msdn.com/tess/archive/2006/08/11/asp-net-quiz-answers-does-page-cache-leak-memory.aspx#9890814</link><pubDate>Thu, 03 Sep 2009 12:29:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9890814</guid><dc:creator>Tess</dc:creator><description>&lt;p&gt;Regarding dasveed's comment.&lt;/p&gt;
&lt;p&gt;The Cache Total entries includes both Cache API entries i.e. Cache.Add(...) or Cache[&amp;quot;...&amp;quot;] = ... &amp;nbsp;, output cache, sessions etc.&lt;/p&gt;
&lt;p&gt;There are two counters that you can use to determine when the cache will be scavenged.&lt;/p&gt;
&lt;p&gt;Cache % Machine Memory Limit used = &amp;quot;The amount of physical memory used by the machine divided by the physical memory limit for the cache, as a percentage. &amp;nbsp;When this reaches 100%, half of the cache entries will be forcibly removed. &amp;nbsp;The __Total__ instance is the average of all instances, and therefore cannot be used to determine when cache entries will be forcibly removed.&amp;quot;&lt;/p&gt;
&lt;p&gt;and &lt;/p&gt;
&lt;p&gt;Cache % Process Memory Limit Used = &amp;quot;The value of private bytes for the worker process divided by the private bytes memory limit for the cache, as a percentage. &amp;nbsp;When this reaches 100%, half of the cache entries will be forcibly removed. &amp;nbsp;The __Total__ instance is the average of all instances, and therefore cannot be used to determine when cache entries will be forcibly removed.&amp;quot;&lt;/p&gt;
&lt;p&gt;You can partially decide when cache will be scavenged by setting the Memory limit settings on the application pool. &amp;nbsp;These values are used to determine if the cache should be scavenged or not. At that point it will scavenge as many cached items as it needs to recover memory. &amp;nbsp; &lt;/p&gt;
&lt;p&gt;To make sure a particluar cached object stays cached until it expires you can set it to non-removable (which is done for the session for example). &amp;nbsp;All other cached objects should be seen as items that could potentially be removed if needed and should be tested for their existence when used. &lt;/p&gt;
&lt;p&gt;Re. the 2nd question about how the cache is stored internally. &amp;nbsp;Simplified, the cache is a static variable with a list of cacheitems referencing the actual cached items. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;In-proc session state uses the cache by caching a session item per session with a dictionary of session vars. &amp;nbsp;The cached session is set to non-removable and has the expiration time set to a sliding expiration of for example 20 mins if that is the session timeout. &lt;/p&gt;
&lt;p&gt;hope that helps&lt;/p&gt;
</description></item></channel></rss>