<?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>Controls are like diapers: you don't want a leaky one [Implementing the WeakEvent pattern on Silverlight with the WeakEventListener class]</title><link>http://blogs.msdn.com/b/delay/archive/2009/03/09/controls-are-like-diapers-you-don-t-want-a-leaky-one-implementing-the-weakevent-pattern-on-silverlight-with-the-weakeventlistener-class.aspx</link><description>One of the nice things about developing on a platform that uses a garbage collecting memory manager (like Silverlight and WPF) is that the traditional concerns about memory leaks pretty much go away; most common types of memory leaks are impossible in</description><dc:language>en</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Controls are like diapers: you don't want a leaky one [Implementing the WeakEvent pattern on Silverlight with the WeakEventListener class]</title><link>http://blogs.msdn.com/b/delay/archive/2009/03/09/controls-are-like-diapers-you-don-t-want-a-leaky-one-implementing-the-weakevent-pattern-on-silverlight-with-the-weakeventlistener-class.aspx#10214194</link><pubDate>Tue, 20 Sep 2011 18:05:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10214194</guid><dc:creator>kmkuntz</dc:creator><description>&lt;p&gt;Yes sir that&amp;#39;s what I&amp;#39;m doing - trying to figure out how to use their patched DragDropTarget. &amp;nbsp;Looks like I&amp;#39;ll have to grab the entire toolkit source unless there&amp;#39;s something I&amp;#39;m missing (which is entirely likely). &amp;nbsp;&lt;/p&gt;
&lt;p&gt;I appreciate all the help David. &amp;nbsp;This would have been quite a bit more difficult without the back and forth.&lt;/p&gt;
&lt;p&gt;Kevin&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10214194" width="1" height="1"&gt;</description></item><item><title>re: Controls are like diapers: you don't want a leaky one [Implementing the WeakEvent pattern on Silverlight with the WeakEventListener class]</title><link>http://blogs.msdn.com/b/delay/archive/2009/03/09/controls-are-like-diapers-you-don-t-want-a-leaky-one-implementing-the-weakevent-pattern-on-silverlight-with-the-weakeventlistener-class.aspx#10214169</link><pubDate>Tue, 20 Sep 2011 17:32:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10214169</guid><dc:creator>David Anson</dc:creator><description>&lt;p&gt;Kevin,&lt;/p&gt;
&lt;p&gt;Sorry about the trouble! However, from the comments of the issue you link to, it looks like folks may have been able to fix the leak. If you have time to experiment, maybe that would resolve the leak without requiring you to abandon the panel?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10214169" width="1" height="1"&gt;</description></item><item><title>re: Controls are like diapers: you don't want a leaky one [Implementing the WeakEvent pattern on Silverlight with the WeakEventListener class]</title><link>http://blogs.msdn.com/b/delay/archive/2009/03/09/controls-are-like-diapers-you-don-t-want-a-leaky-one-implementing-the-weakevent-pattern-on-silverlight-with-the-weakeventlistener-class.aspx#10214136</link><pubDate>Tue, 20 Sep 2011 16:01:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10214136</guid><dc:creator>kmkuntz</dc:creator><description>&lt;p&gt;Using WinDbg I was able to locate the source of my memory leak (good!). &amp;nbsp;Turns out it is caused by the use of a PanelDragDropTarget (bad!), as discussed here: &amp;nbsp;&lt;a rel="nofollow" target="_new" href="http://silverlight.codeplex.com/workitem/7356"&gt;silverlight.codeplex.com/.../7356&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Not sure how to resolve this one other than removing the panel, which will also remove functionality that our users are used to having.&lt;/p&gt;
&lt;p&gt;Thanks for the advice. &amp;nbsp;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10214136" width="1" height="1"&gt;</description></item><item><title>re: Controls are like diapers: you don't want a leaky one [Implementing the WeakEvent pattern on Silverlight with the WeakEventListener class]</title><link>http://blogs.msdn.com/b/delay/archive/2009/03/09/controls-are-like-diapers-you-don-t-want-a-leaky-one-implementing-the-weakevent-pattern-on-silverlight-with-the-weakeventlistener-class.aspx#10214068</link><pubDate>Tue, 20 Sep 2011 13:48:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10214068</guid><dc:creator>kmkuntz</dc:creator><description>&lt;p&gt;Thanks for your help David. &amp;nbsp;That clears up a lot.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10214068" width="1" height="1"&gt;</description></item><item><title>re: Controls are like diapers: you don't want a leaky one [Implementing the WeakEvent pattern on Silverlight with the WeakEventListener class]</title><link>http://blogs.msdn.com/b/delay/archive/2009/03/09/controls-are-like-diapers-you-don-t-want-a-leaky-one-implementing-the-weakevent-pattern-on-silverlight-with-the-weakeventlistener-class.aspx#10213877</link><pubDate>Tue, 20 Sep 2011 05:13:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10213877</guid><dc:creator>David Anson</dc:creator><description>&lt;p&gt;Kevin,&lt;/p&gt;
&lt;p&gt;Your understanding is correct: if the thing subscribing to the event has the same lifetime as the thing that exposes the event, there shouldn&amp;#39;t be a leak concern because both instances will become garbage at the same time and the fact that one references the other won&amp;#39;t matter. The big concern is when there&amp;#39;s a long-lived (i.e., for the life of the application) collection with one of these &amp;quot;backward references&amp;quot; to an individual page instance - especially if that new instances of that page are created regularly! :)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10213877" width="1" height="1"&gt;</description></item><item><title>re: Controls are like diapers: you don't want a leaky one [Implementing the WeakEvent pattern on Silverlight with the WeakEventListener class]</title><link>http://blogs.msdn.com/b/delay/archive/2009/03/09/controls-are-like-diapers-you-don-t-want-a-leaky-one-implementing-the-weakevent-pattern-on-silverlight-with-the-weakeventlistener-class.aspx#10213497</link><pubDate>Mon, 19 Sep 2011 14:30:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10213497</guid><dc:creator>kmkuntz</dc:creator><description>&lt;p&gt;Thanks for the response. &amp;nbsp;I&amp;#39;ll set the source to null upon leaving the view for sanity&amp;#39;s sake, and will be checking out windbg immediately.&lt;/p&gt;
&lt;p&gt;one last one - what about a simple, completely self-contained button click handler defined on my view for a button on my view? &amp;nbsp;does that need to be unregistered? &amp;nbsp;If the button is defined on the view it would seem that it should have the same lifetime as the view, and therefore shouldn&amp;#39;t be a problem. &amp;nbsp;it will die when the view goes, regardless of the handler.&lt;/p&gt;
&lt;p&gt;is this correct? &amp;nbsp;or should ALL handlers be unregistered? &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks for your time.&lt;/p&gt;
&lt;p&gt;Kevin&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10213497" width="1" height="1"&gt;</description></item><item><title>re: Controls are like diapers: you don't want a leaky one [Implementing the WeakEvent pattern on Silverlight with the WeakEventListener class]</title><link>http://blogs.msdn.com/b/delay/archive/2009/03/09/controls-are-like-diapers-you-don-t-want-a-leaky-one-implementing-the-weakevent-pattern-on-silverlight-with-the-weakeventlistener-class.aspx#10212663</link><pubDate>Fri, 16 Sep 2011 21:06:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10212663</guid><dc:creator>David Anson</dc:creator><description>&lt;p&gt;Kevin,&lt;/p&gt;
&lt;p&gt;Yes, it seems like the reference to App.StaticObservableCollectionA will remain present even when the view isn&amp;#39;t current. HOWEVER, the platform&amp;#39;s ItemsControl class (upon which ComboBox is built) already does the right thing here to maintain weak references, so this shouldn&amp;#39;t be the source of a leak for you (assuming this isn&amp;#39;t a platform bug). That said, if you want to help be *sure* and cover all the bases, you should be able to set the ItemsSource to null in an Unloaded handler for your view (the counterpart to the Loaded handler you&amp;#39;re already using). Alternatively, maybe do the attach/detach as part of the OnNavigatedTo/From process.&lt;/p&gt;
&lt;p&gt;You also might find it helpful to try to determine the source of the possible leak using the process I describe here: &lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/b/delay/archive/2009/03/11/where-s-your-leak-at-using-windbg-sos-and-gcroot-to-diagnose-a-net-memory-leak.aspx"&gt;blogs.msdn.com/.../where-s-your-leak-at-using-windbg-sos-and-gcroot-to-diagnose-a-net-memory-leak.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hope this helps!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10212663" width="1" height="1"&gt;</description></item><item><title>re: Controls are like diapers: you don't want a leaky one [Implementing the WeakEvent pattern on Silverlight with the WeakEventListener class]</title><link>http://blogs.msdn.com/b/delay/archive/2009/03/09/controls-are-like-diapers-you-don-t-want-a-leaky-one-implementing-the-weakevent-pattern-on-silverlight-with-the-weakeventlistener-class.aspx#10212623</link><pubDate>Fri, 16 Sep 2011 19:53:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10212623</guid><dc:creator>Kevin</dc:creator><description>&lt;p&gt;Hi Delay - I have a question regarding implementation of the above.&lt;/p&gt;
&lt;p&gt;I have a SL navigation view with the following code (in the Loaded handler):&lt;/p&gt;
&lt;p&gt;ComboBoxA.ItemsSource = null;&lt;/p&gt;
&lt;p&gt;ComboBoxA.ItemsSource = App.StaticObservableCollectionA;&lt;/p&gt;
&lt;p&gt;App.StaticObservableCollectionA is an ObservableCollection&amp;lt;Entity&amp;gt; - stored in App.xaml as a public static property, like so:&lt;/p&gt;
&lt;p&gt;public static ObservableCollection&amp;lt;Business_Role&amp;gt; StaticObservableCollectionA { get; set; }&lt;/p&gt;
&lt;p&gt;question one - this looks like a scenario that will cause my view to stay in memory even though i&amp;#39;ve navigated away from it. &amp;nbsp;right?&lt;/p&gt;
&lt;p&gt;question two - if the answer to question one is yes, how do I use this pattern to alleviate this problem? &amp;nbsp;for better or worse, i have this all over my app...&lt;/p&gt;
&lt;p&gt;the memory creeps and creeps as i move to and from views in this app. &amp;nbsp;I&amp;#39;d like to put a lid on it. &amp;nbsp;Thanks for your help. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kevin&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10212623" width="1" height="1"&gt;</description></item><item><title>re: Controls are like diapers: you don't want a leaky one [Implementing the WeakEvent pattern on Silverlight with the WeakEventListener class]</title><link>http://blogs.msdn.com/b/delay/archive/2009/03/09/controls-are-like-diapers-you-don-t-want-a-leaky-one-implementing-the-weakevent-pattern-on-silverlight-with-the-weakeventlistener-class.aspx#10139926</link><pubDate>Fri, 11 Mar 2011 17:37:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10139926</guid><dc:creator>David Anson</dc:creator><description>&lt;p&gt;Jamil,&lt;/p&gt;
&lt;p&gt;The code I post is under the Microsoft Public License (Ms-PL). There&amp;#39;s a link to the full license from the &amp;quot;Information&amp;quot; section in the sidebar at the top of every post. The high-level summary is that you can use the code for pretty much anything you want. :)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10139926" width="1" height="1"&gt;</description></item><item><title>re: Controls are like diapers: you don't want a leaky one [Implementing the WeakEvent pattern on Silverlight with the WeakEventListener class]</title><link>http://blogs.msdn.com/b/delay/archive/2009/03/09/controls-are-like-diapers-you-don-t-want-a-leaky-one-implementing-the-weakevent-pattern-on-silverlight-with-the-weakeventlistener-class.aspx#10139788</link><pubDate>Fri, 11 Mar 2011 11:25:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10139788</guid><dc:creator>Jamil</dc:creator><description>&lt;p&gt;Guys what the license for using WeakEventListener class in my code ?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10139788" width="1" height="1"&gt;</description></item></channel></rss>