<?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: Why you should always unscubscribe event handlers</title>
	<atom:link href="http://davybrion.com/blog/2008/08/why-you-should-always-unscubscribe-event-handlers/feed/" rel="self" type="application/rss+xml" />
	<link>http://davybrion.com/blog/2008/08/why-you-should-always-unscubscribe-event-handlers/</link>
	<description>Trying to walk that thin line between intelligence and ignorance</description>
	<lastBuildDate>Sun, 14 Mar 2010 15:41:46 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Bradley Grainger</title>
		<link>http://davybrion.com/blog/2008/08/why-you-should-always-unscubscribe-event-handlers/comment-page-1/#comment-1462</link>
		<dc:creator>Bradley Grainger</dc:creator>
		<pubDate>Thu, 28 Aug 2008 02:59:51 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=325#comment-1462</guid>
		<description>Coincidentally, we also recently blogged about unsubscribing from events (http://code.logos.com/blog/2008/08/unsubscribing_from_c_events.html) and how to set up a &quot;weak&quot; subscription (which allows the subscriber to be garbage-collected) to any event, without having to modify the event publisher: http://code.logos.com/blog/2008/08/event_subscription_using_weak_references.html.</description>
		<content:encoded><![CDATA[<p>Coincidentally, we also recently blogged about unsubscribing from events (<a href="http://code.logos.com/blog/2008/08/unsubscribing_from_c_events.html" rel="nofollow">http://code.logos.com/blog/2008/08/unsubscribing_from_c_events.html</a>) and how to set up a &#8220;weak&#8221; subscription (which allows the subscriber to be garbage-collected) to any event, without having to modify the event publisher: <a href="http://code.logos.com/blog/2008/08/event_subscription_using_weak_references.html" rel="nofollow">http://code.logos.com/blog/2008/08/event_subscription_using_weak_references.html</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Interesting Finds: 2008.08.13~2008.08.21 - gOODiDEA.NET</title>
		<link>http://davybrion.com/blog/2008/08/why-you-should-always-unscubscribe-event-handlers/comment-page-1/#comment-1312</link>
		<dc:creator>Interesting Finds: 2008.08.13~2008.08.21 - gOODiDEA.NET</dc:creator>
		<pubDate>Thu, 21 Aug 2008 11:09:35 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=325#comment-1312</guid>
		<description>[...] Why you should always unscubscribe event handlers [...]</description>
		<content:encoded><![CDATA[<p>[...] Why you should always unscubscribe event handlers [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2008/08/why-you-should-always-unscubscribe-event-handlers/comment-page-1/#comment-1284</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Wed, 20 Aug 2008 05:34:45 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=325#comment-1284</guid>
		<description>Not for typical UI scenario&#039;s where the form or the page subscribes to an event of one of the controls that is owned by the form or the page.  In that situation, the form/page is the Subscriber and is also the only owner of the Publisher.  If the Subscriber is cleaned up, the Publisher automatically goes with it so then there&#039;s no problem.  Both instances will be cleaned up without having to explicitely unsubscribe from the events.

If external objects (instances of other classes or other forms or whatever) subscribe to an event of a Form/Page, then you do have to be pretty careful and you should definitely follow the rule.</description>
		<content:encoded><![CDATA[<p>Not for typical UI scenario&#8217;s where the form or the page subscribes to an event of one of the controls that is owned by the form or the page.  In that situation, the form/page is the Subscriber and is also the only owner of the Publisher.  If the Subscriber is cleaned up, the Publisher automatically goes with it so then there&#8217;s no problem.  Both instances will be cleaned up without having to explicitely unsubscribe from the events.</p>
<p>If external objects (instances of other classes or other forms or whatever) subscribe to an event of a Form/Page, then you do have to be pretty careful and you should definitely follow the rule.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kiran</title>
		<link>http://davybrion.com/blog/2008/08/why-you-should-always-unscubscribe-event-handlers/comment-page-1/#comment-1280</link>
		<dc:creator>Kiran</dc:creator>
		<pubDate>Wed, 20 Aug 2008 00:27:54 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=325#comment-1280</guid>
		<description>Does this rule apply in UI scenarios? (WinForms/Asp.Net).  

If the answer is yes, do we need to write unsubscription code for every UI element that we subscribe in a form/page?  That doesn&#039;t seem normal!

If the answer is No, and if the responsibility of &#039;unsubscribing&#039; is on subscriber, how the asp.net/winforms publishers are cleaning up the bad subscribers?</description>
		<content:encoded><![CDATA[<p>Does this rule apply in UI scenarios? (WinForms/Asp.Net).  </p>
<p>If the answer is yes, do we need to write unsubscription code for every UI element that we subscribe in a form/page?  That doesn&#8217;t seem normal!</p>
<p>If the answer is No, and if the responsibility of &#8216;unsubscribing&#8217; is on subscriber, how the asp.net/winforms publishers are cleaning up the bad subscribers?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reflective Perspective - Chris Alcock &#187; The Morning Brew #161</title>
		<link>http://davybrion.com/blog/2008/08/why-you-should-always-unscubscribe-event-handlers/comment-page-1/#comment-1262</link>
		<dc:creator>Reflective Perspective - Chris Alcock &#187; The Morning Brew #161</dc:creator>
		<pubDate>Tue, 19 Aug 2008 08:09:21 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=325#comment-1262</guid>
		<description>[...] Why you should always unsubscribe event handlers - Davy Brion talks about one of the most common causes of memory problems caused by the Garbage collector not being able to remove object because other objects still hold references to them via event handlers. [...]</description>
		<content:encoded><![CDATA[<p>[...] Why you should always unsubscribe event handlers &#8211; Davy Brion talks about one of the most common causes of memory problems caused by the Garbage collector not being able to remove object because other objects still hold references to them via event handlers. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2008/08/why-you-should-always-unscubscribe-event-handlers/comment-page-1/#comment-1256</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Tue, 19 Aug 2008 05:22:22 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=325#comment-1256</guid>
		<description>if it&#039;s not in an interactive scenario (UI stuff), i prefer to use waithandles for async stuff though. But your point is definitely valid... in this case it wouldn&#039;t make sense to unsubscribe from the events</description>
		<content:encoded><![CDATA[<p>if it&#8217;s not in an interactive scenario (UI stuff), i prefer to use waithandles for async stuff though. But your point is definitely valid&#8230; in this case it wouldn&#8217;t make sense to unsubscribe from the events</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David N</title>
		<link>http://davybrion.com/blog/2008/08/why-you-should-always-unscubscribe-event-handlers/comment-page-1/#comment-1243</link>
		<dc:creator>David N</dc:creator>
		<pubDate>Mon, 18 Aug 2008 21:45:12 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=325#comment-1243</guid>
		<description>Think about an async request that calls back or publishes some &#039;completed&#039; event. Like you said, a somewhat niche case, but still happens enough that it&#039;s a valid (and simplifying) use.</description>
		<content:encoded><![CDATA[<p>Think about an async request that calls back or publishes some &#8216;completed&#8217; event. Like you said, a somewhat niche case, but still happens enough that it&#8217;s a valid (and simplifying) use.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2008/08/why-you-should-always-unscubscribe-event-handlers/comment-page-1/#comment-1237</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Mon, 18 Aug 2008 18:45:36 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=325#comment-1237</guid>
		<description>&quot;Until that change is introduced, letting the objects die is fine.&quot;

If they are all short-lived objects (for instance, to handle some kind of request like you mention) and their life cycle won&#039;t ever change, then yeah, it&#039;s ok. Although i generally never create short-lived Publishers... i&#039;m sure there are scenario&#039;s where it makes sense but in most cases i think it would just make things more &#039;complicated&#039; than they need to be</description>
		<content:encoded><![CDATA[<p>&#8220;Until that change is introduced, letting the objects die is fine.&#8221;</p>
<p>If they are all short-lived objects (for instance, to handle some kind of request like you mention) and their life cycle won&#8217;t ever change, then yeah, it&#8217;s ok. Although i generally never create short-lived Publishers&#8230; i&#8217;m sure there are scenario&#8217;s where it makes sense but in most cases i think it would just make things more &#8216;complicated&#8217; than they need to be</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David N</title>
		<link>http://davybrion.com/blog/2008/08/why-you-should-always-unscubscribe-event-handlers/comment-page-1/#comment-1236</link>
		<dc:creator>David N</dc:creator>
		<pubDate>Mon, 18 Aug 2008 18:27:07 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=325#comment-1236</guid>
		<description>&gt;even if they have the same lifetime, if at some point a change is introduced which extends B’s &gt;lifetime, A will not be cleaned up and it will keep on receiving the event

But that&#039;s the point. Until that change is introduced, letting the objects die is fine. I have a case right now where I&#039;m creating a request object which creates and then passes control to its child objects. No need to deregister listening to their events, bc when it goes they all go.

As always, you have to think about context.</description>
		<content:encoded><![CDATA[<p>&gt;even if they have the same lifetime, if at some point a change is introduced which extends B’s &gt;lifetime, A will not be cleaned up and it will keep on receiving the event</p>
<p>But that&#8217;s the point. Until that change is introduced, letting the objects die is fine. I have a case right now where I&#8217;m creating a request object which creates and then passes control to its child objects. No need to deregister listening to their events, bc when it goes they all go.</p>
<p>As always, you have to think about context.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David McClelland</title>
		<link>http://davybrion.com/blog/2008/08/why-you-should-always-unscubscribe-event-handlers/comment-page-1/#comment-1235</link>
		<dc:creator>David McClelland</dc:creator>
		<pubDate>Mon, 18 Aug 2008 18:10:23 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=325#comment-1235</guid>
		<description>That reminds me of Microsoft&#039;s advice back in the .NET 1.x days for avoiding memory leaks when using WinForms data binding:  always call [control].DataBindings.Clear()

http://msdn.microsoft.com/en-us/library/ms996446.aspx#databinding_winforms10_11_topic11

Those were the good old days...  oh wait!  Those days are still here!!!

:-)

- David McClelland</description>
		<content:encoded><![CDATA[<p>That reminds me of Microsoft&#8217;s advice back in the .NET 1.x days for avoiding memory leaks when using WinForms data binding:  always call [control].DataBindings.Clear()</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms996446.aspx#databinding_winforms10_11_topic11" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms996446.aspx#databinding_winforms10_11_topic11</a></p>
<p>Those were the good old days&#8230;  oh wait!  Those days are still here!!!</p>
<p> <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>- David McClelland</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2008/08/why-you-should-always-unscubscribe-event-handlers/comment-page-1/#comment-1229</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Mon, 18 Aug 2008 17:08:41 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=325#comment-1229</guid>
		<description>everything that&#039;s static has the possibility to become a pain in the ass ;)</description>
		<content:encoded><![CDATA[<p>everything that&#8217;s static has the possibility to become a pain in the ass <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cherian Thomas</title>
		<link>http://davybrion.com/blog/2008/08/why-you-should-always-unscubscribe-event-handlers/comment-page-1/#comment-1228</link>
		<dc:creator>Cherian Thomas</dc:creator>
		<pubDate>Mon, 18 Aug 2008 17:02:55 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=325#comment-1228</guid>
		<description>Life becomes horrible if its a static event and you don&#039;t follow these practices :-)</description>
		<content:encoded><![CDATA[<p>Life becomes horrible if its a static event and you don&#8217;t follow these practices <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2008/08/why-you-should-always-unscubscribe-event-handlers/comment-page-1/#comment-1227</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Mon, 18 Aug 2008 16:34:10 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=325#comment-1227</guid>
		<description>even if they have the same lifetime, if at some point a change is introduced which extends B&#039;s lifetime, A will not be cleaned up and it will keep on receiving the event</description>
		<content:encoded><![CDATA[<p>even if they have the same lifetime, if at some point a change is introduced which extends B&#8217;s lifetime, A will not be cleaned up and it will keep on receiving the event</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David N</title>
		<link>http://davybrion.com/blog/2008/08/why-you-should-always-unscubscribe-event-handlers/comment-page-1/#comment-1226</link>
		<dc:creator>David N</dc:creator>
		<pubDate>Mon, 18 Aug 2008 16:26:48 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=325#comment-1226</guid>
		<description>It depends on the context. If object A is listening to object B, yet they both have the same lifetime (i.e. they die together), you don&#039;t need to deregister any events.

Deregistering is also less trivial when it comes to anonymous delegates.</description>
		<content:encoded><![CDATA[<p>It depends on the context. If object A is listening to object B, yet they both have the same lifetime (i.e. they die together), you don&#8217;t need to deregister any events.</p>
<p>Deregistering is also less trivial when it comes to anonymous delegates.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2008/08/why-you-should-always-unscubscribe-event-handlers/comment-page-1/#comment-1218</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Mon, 18 Aug 2008 09:54:35 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=325#comment-1218</guid>
		<description>That wouldn&#039;t work with regular events, so you&#039;d have to write custom code to get that working and then you&#039;d have to use that &#039;non-standard&#039; mechanism throughout your code base

at that point it&#039;s probably easier to just make sure each subscriber offers a way to unsubscribe from the events</description>
		<content:encoded><![CDATA[<p>That wouldn&#8217;t work with regular events, so you&#8217;d have to write custom code to get that working and then you&#8217;d have to use that &#8216;non-standard&#8217; mechanism throughout your code base</p>
<p>at that point it&#8217;s probably easier to just make sure each subscriber offers a way to unsubscribe from the events</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cherian Thomas</title>
		<link>http://davybrion.com/blog/2008/08/why-you-should-always-unscubscribe-event-handlers/comment-page-1/#comment-1212</link>
		<dc:creator>Cherian Thomas</dc:creator>
		<pubDate>Mon, 18 Aug 2008 08:42:35 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=325#comment-1212</guid>
		<description>Do you think it’s wise to make the subscriber register a weak reference?</description>
		<content:encoded><![CDATA[<p>Do you think it’s wise to make the subscriber register a weak reference?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
