<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: WPF &amp; Memory Leaks</title>
	<atom:link href="http://www.cplotts.com/2009/04/14/wpf-memory-leaks/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cplotts.com/2009/04/14/wpf-memory-leaks/</link>
	<description>Yet another UX guy, working in WPF/Silverlight.</description>
	<lastBuildDate>Mon, 16 Jan 2012 15:35:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: rubenhak.com &#187; Identifying and Solving C#/WPF Memory Leaks</title>
		<link>http://www.cplotts.com/2009/04/14/wpf-memory-leaks/comment-page-1/#comment-704</link>
		<dc:creator>rubenhak.com &#187; Identifying and Solving C#/WPF Memory Leaks</dc:creator>
		<pubDate>Wed, 30 Jun 2010 16:37:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.cplotts.com/?p=161#comment-704</guid>
		<description>[...] WPF &amp; Memory Leaks [...]</description>
		<content:encoded><![CDATA[<p>[...] WPF &amp; Memory Leaks [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cplotts</title>
		<link>http://www.cplotts.com/2009/04/14/wpf-memory-leaks/comment-page-1/#comment-286</link>
		<dc:creator>cplotts</dc:creator>
		<pubDate>Wed, 25 Nov 2009 20:28:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.cplotts.com/?p=161#comment-286</guid>
		<description>Eric Harding of Microsoft says that they use the .NET Memory Profiler internally on the WPF performance team.

Check out the following PDC &lt;a href=&quot;http://microsoftpdc.com/Sessions/CL11&quot; rel=&quot;nofollow&quot;&gt;session&lt;/a&gt; where he states that. For that matter, that session is just a great session on WPF performance problems and how to use tools to solve them.</description>
		<content:encoded><![CDATA[<p>Eric Harding of Microsoft says that they use the .NET Memory Profiler internally on the WPF performance team.</p>
<p>Check out the following PDC <a href="http://microsoftpdc.com/Sessions/CL11" rel="nofollow">session</a> where he states that. For that matter, that session is just a great session on WPF performance problems and how to use tools to solve them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Harrop</title>
		<link>http://www.cplotts.com/2009/04/14/wpf-memory-leaks/comment-page-1/#comment-156</link>
		<dc:creator>Jon Harrop</dc:creator>
		<pubDate>Wed, 23 Sep 2009 14:06:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.cplotts.com/?p=161#comment-156</guid>
		<description>Red Gate were kind enough to send me a free copy of their ANTS profiler for review. Unfortunately, I never published the review in our literature because it just crashed over and over. Turns out it does not fully support .NET CIL and many of our programs use ILX that causes the ANTS profiler to crash.</description>
		<content:encoded><![CDATA[<p>Red Gate were kind enough to send me a free copy of their ANTS profiler for review. Unfortunately, I never published the review in our literature because it just crashed over and over. Turns out it does not fully support .NET CIL and many of our programs use ILX that causes the ANTS profiler to crash.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cplotts</title>
		<link>http://www.cplotts.com/2009/04/14/wpf-memory-leaks/comment-page-1/#comment-155</link>
		<dc:creator>cplotts</dc:creator>
		<pubDate>Tue, 08 Sep 2009 14:30:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.cplotts.com/?p=161#comment-155</guid>
		<description>&lt;a href=&quot;#comment-154&quot; rel=&quot;nofollow&quot;&gt;@Clint &lt;/a&gt; 

Thanks Clint, glad you liked the post. I wrote it so that my pain could be other people&#039;s gain.

As I understand your comment, it seems as if you are running afoul of what I was calling the &#039;Red Herring&#039;. It is definitely a bug, and one (as you have noted) that they have &lt;a href=&quot;http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b97a5f83-5394-430e-9a78-9d3a957e3537&quot; rel=&quot;nofollow&quot;&gt;fixed&lt;/a&gt;. However, I could never verify that it was causing us issues in our running application. In every place that I checked, inflation of the resource caused it to detach and not leak.

It seems as if you found a situation where it still leaks even if the UserControl becomes part of the visual tree. Well, I guess I am assuming that _userControlPlaceholder is being shown on the screen ... is that the case?

Regardless, all that being said, I would say that the workaround would be to use StaticResource(s) instead of DynamicResource(s). Of course, this would eliminite the possibility of &#039;on-the-fly&#039; skinning. We ourselves just left things the way the are ... as the big leak by far ... was the one that occurs with data binding.

Good luck ... thanks for commenting!</description>
		<content:encoded><![CDATA[<p><a href="#comment-154" rel="nofollow">@Clint </a> </p>
<p>Thanks Clint, glad you liked the post. I wrote it so that my pain could be other people&#8217;s gain.</p>
<p>As I understand your comment, it seems as if you are running afoul of what I was calling the &#8216;Red Herring&#8217;. It is definitely a bug, and one (as you have noted) that they have <a href="http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b97a5f83-5394-430e-9a78-9d3a957e3537" rel="nofollow">fixed</a>. However, I could never verify that it was causing us issues in our running application. In every place that I checked, inflation of the resource caused it to detach and not leak.</p>
<p>It seems as if you found a situation where it still leaks even if the UserControl becomes part of the visual tree. Well, I guess I am assuming that _userControlPlaceholder is being shown on the screen &#8230; is that the case?</p>
<p>Regardless, all that being said, I would say that the workaround would be to use StaticResource(s) instead of DynamicResource(s). Of course, this would eliminite the possibility of &#8216;on-the-fly&#8217; skinning. We ourselves just left things the way the are &#8230; as the big leak by far &#8230; was the one that occurs with data binding.</p>
<p>Good luck &#8230; thanks for commenting!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Clint</title>
		<link>http://www.cplotts.com/2009/04/14/wpf-memory-leaks/comment-page-1/#comment-154</link>
		<dc:creator>Clint</dc:creator>
		<pubDate>Tue, 08 Sep 2009 12:16:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.cplotts.com/?p=161#comment-154</guid>
		<description>Very good post Cory!  I have also managed to fall foul to this subtle bug too… I cannot believe this is not *the* major issue for WPF out there (maybe people aren’t really shipping real world apps in WPF yet?) Here’s my very simplified scenario:

I have resource dictionaries:

 Colors.xaml – with:
	&lt;Color x:Key=&quot;BackgroundColor&quot;&gt;#FF6699CC&lt;/Color&gt;

Brushes.xaml – with (note dynamic and static resource references in color prop):
	&lt;SolidColorBrush x:Key=&quot;DynamicBackgroundBrush&quot; Color=&quot;{DynamicResource BackgroundColor}&quot;/&gt;
	&lt;SolidColorBrush x:Key=&quot;StaticBackgroundBrush&quot; Color=&quot;{StaticResource BackgroundColor}&quot;/&gt;

I have UserControl1.xaml and Usercontrol2.xaml.

In user control 1 I use DynamicBackgroundBrush for a border background.
In user control 2 I use StaticBackgroundBrush for a border background.

In Window1.xaml
I use a button to swap the ContentProperty of a ContentControl  to either UserControl  1 or 2 to toggle between the two (like one would using CAL/PRISM if you use ContentControl regions to present different views).

	if(_userControlPlaceholder.Content is UserControl1)
		_userControlPlaceholder.Content = new UserControl2();
	else
		_userControlPlaceholder.Content = new UserControl1();
The result is that UserControl1 leaks and UserControl2 does not. This seems to be due to the fact that Color &lt;- SolidColorBrush &lt;- Border.Background where the refs are all DynamicResource refs.

Bear in mind that this is a simplified scenario to show the issue and that it is especially subtle when control templates are involves which exist in separate resource dictionary  files in which it is sometimes difficult to use a StaticResource reference.

What has been your workaround to this? I have verified that it is fixed in .NET 4.0 (Beta) but what to do for now?

BTW – .NET Memory Profiler flagged this immediately with a &#039;Direct EventHandler roots&#039; warning – great tool!</description>
		<content:encoded><![CDATA[<p>Very good post Cory!  I have also managed to fall foul to this subtle bug too… I cannot believe this is not *the* major issue for WPF out there (maybe people aren’t really shipping real world apps in WPF yet?) Here’s my very simplified scenario:</p>
<p>I have resource dictionaries:</p>
<p> Colors.xaml – with:<br />
	&lt;Color x:Key=&quot;BackgroundColor&quot;&gt;#FF6699CC&lt;/Color&gt;</p>
<p>Brushes.xaml – with (note dynamic and static resource references in color prop):<br />
	&lt;SolidColorBrush x:Key=&quot;DynamicBackgroundBrush&quot; Color=&quot;{DynamicResource BackgroundColor}&quot;/&gt;<br />
	&lt;SolidColorBrush x:Key=&quot;StaticBackgroundBrush&quot; Color=&quot;{StaticResource BackgroundColor}&quot;/&gt;</p>
<p>I have UserControl1.xaml and Usercontrol2.xaml.</p>
<p>In user control 1 I use DynamicBackgroundBrush for a border background.<br />
In user control 2 I use StaticBackgroundBrush for a border background.</p>
<p>In Window1.xaml<br />
I use a button to swap the ContentProperty of a ContentControl  to either UserControl  1 or 2 to toggle between the two (like one would using CAL/PRISM if you use ContentControl regions to present different views).</p>
<p>	if(_userControlPlaceholder.Content is UserControl1)<br />
		_userControlPlaceholder.Content = new UserControl2();<br />
	else<br />
		_userControlPlaceholder.Content = new UserControl1();<br />
The result is that UserControl1 leaks and UserControl2 does not. This seems to be due to the fact that Color &lt;- SolidColorBrush &lt;- Border.Background where the refs are all DynamicResource refs.</p>
<p>Bear in mind that this is a simplified scenario to show the issue and that it is especially subtle when control templates are involves which exist in separate resource dictionary  files in which it is sometimes difficult to use a StaticResource reference.</p>
<p>What has been your workaround to this? I have verified that it is fixed in .NET 4.0 (Beta) but what to do for now?</p>
<p>BTW – .NET Memory Profiler flagged this immediately with a &#8216;Direct EventHandler roots&#8217; warning – great tool!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cplotts</title>
		<link>http://www.cplotts.com/2009/04/14/wpf-memory-leaks/comment-page-1/#comment-119</link>
		<dc:creator>cplotts</dc:creator>
		<pubDate>Mon, 03 Aug 2009 13:10:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.cplotts.com/?p=161#comment-119</guid>
		<description>I have not tried Red Gate&#039;s ANTS Memory Profiler. I stopped trying different ones out once I ran into SciTech&#039;s .NET Memory Profiler. I&#039;ll have to give it a look.</description>
		<content:encoded><![CDATA[<p>I have not tried Red Gate&#8217;s ANTS Memory Profiler. I stopped trying different ones out once I ran into SciTech&#8217;s .NET Memory Profiler. I&#8217;ll have to give it a look.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Laila Lotfi</title>
		<link>http://www.cplotts.com/2009/04/14/wpf-memory-leaks/comment-page-1/#comment-117</link>
		<dc:creator>Laila Lotfi</dc:creator>
		<pubDate>Mon, 03 Aug 2009 08:39:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.cplotts.com/?p=161#comment-117</guid>
		<description>Nice blog post Cory. Have you tried the latest ANTS Memory Profiler from Red Gate? It’s a major improvement over what it used to be, but you should judge for yourself as I’m a bit biased.</description>
		<content:encoded><![CDATA[<p>Nice blog post Cory. Have you tried the latest ANTS Memory Profiler from Red Gate? It’s a major improvement over what it used to be, but you should judge for yourself as I’m a bit biased.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

