<?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: Moment of Weakness: Weak Event Listeners Can Be Dangerous</title>
	<atom:link href="http://joeberkovitz.com/blog/2007/06/20/moment-of-weakness-weak-event-listeners-can-be-dangerous/feed/" rel="self" type="application/rss+xml" />
	<link>http://joeberkovitz.com/blog/2007/06/20/moment-of-weakness-weak-event-listeners-can-be-dangerous/</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 13 Aug 2010 18:04:58 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Learning Flex &#8211; Lesson 26, The Basics of Memory Management and Performance &#171; M@ Blog</title>
		<link>http://joeberkovitz.com/blog/2007/06/20/moment-of-weakness-weak-event-listeners-can-be-dangerous/comment-page-1/#comment-82327</link>
		<dc:creator>Learning Flex &#8211; Lesson 26, The Basics of Memory Management and Performance &#171; M@ Blog</dc:creator>
		<pubDate>Mon, 08 Mar 2010 01:48:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.joeberkovitz.com/blog/?p=47#comment-82327</guid>
		<description>[...] would be eligible for garbage collection. Here&#8217;s a post with more on weak references and here&#8217;s an opinion on when they shouldn&#8217;t be [...]</description>
		<content:encoded><![CDATA[<p>[...] would be eligible for garbage collection. Here&#8217;s a post with more on weak references and here&#8217;s an opinion on when they shouldn&#8217;t be [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rein</title>
		<link>http://joeberkovitz.com/blog/2007/06/20/moment-of-weakness-weak-event-listeners-can-be-dangerous/comment-page-1/#comment-33121</link>
		<dc:creator>Rein</dc:creator>
		<pubDate>Fri, 03 Apr 2009 10:14:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.joeberkovitz.com/blog/?p=47#comment-33121</guid>
		<description>Thanks so, so much for this article.

I&#039;ve spent 2 and a half day trying to figure something similar out. Turned out to just set one boolean to false would do the trick ;)

Thanks!</description>
		<content:encoded><![CDATA[<p>Thanks so, so much for this article.</p>
<p>I&#8217;ve spent 2 and a half day trying to figure something similar out. Turned out to just set one boolean to false would do the trick ;)</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: joe</title>
		<link>http://joeberkovitz.com/blog/2007/06/20/moment-of-weakness-weak-event-listeners-can-be-dangerous/comment-page-1/#comment-132</link>
		<dc:creator>joe</dc:creator>
		<pubDate>Wed, 16 Jan 2008 00:58:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.joeberkovitz.com/blog/?p=47#comment-132</guid>
		<description>One other note: I continue to be careful with weak refs because problems with premature GCs show up so unreliably and unreproducibly that they are hard to catch in testing.  My approach is to start with strong refs, and then weaken them until memory leaks disappear (hooray for the Profiler).  A memory leak is deterministic: it&#039;s bound to show up if you look for it.  A premature GC might or might not happen.</description>
		<content:encoded><![CDATA[<p>One other note: I continue to be careful with weak refs because problems with premature GCs show up so unreliably and unreproducibly that they are hard to catch in testing.  My approach is to start with strong refs, and then weaken them until memory leaks disappear (hooray for the Profiler).  A memory leak is deterministic: it&#8217;s bound to show up if you look for it.  A premature GC might or might not happen.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: joe</title>
		<link>http://joeberkovitz.com/blog/2007/06/20/moment-of-weakness-weak-event-listeners-can-be-dangerous/comment-page-1/#comment-134</link>
		<dc:creator>joe</dc:creator>
		<pubDate>Wed, 16 Jan 2008 00:55:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.joeberkovitz.com/blog/?p=47#comment-134</guid>
		<description>Well, this continues to be a hot topic.  I am presently tracking down a bunch of memory leaks in an app I wrote with the help of the Flex Builder Profiler, and many of them are amenable to being solved via weak references.  But I also have run into a number of situations in which objects using the Mediator design pattern are prematurely GCed if all their listener references were weak.  Obviously an object such as a Mediator (whose only role is to listen to events from other objects) is not going to stick around unless there is at least one strong ref.  So I continue to maintain that weak refs, while an essential tool, are not a panacea!</description>
		<content:encoded><![CDATA[<p>Well, this continues to be a hot topic.  I am presently tracking down a bunch of memory leaks in an app I wrote with the help of the Flex Builder Profiler, and many of them are amenable to being solved via weak references.  But I also have run into a number of situations in which objects using the Mediator design pattern are prematurely GCed if all their listener references were weak.  Obviously an object such as a Mediator (whose only role is to listen to events from other objects) is not going to stick around unless there is at least one strong ref.  So I continue to maintain that weak refs, while an essential tool, are not a panacea!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Dumke</title>
		<link>http://joeberkovitz.com/blog/2007/06/20/moment-of-weakness-weak-event-listeners-can-be-dangerous/comment-page-1/#comment-133</link>
		<dc:creator>David Dumke</dc:creator>
		<pubDate>Wed, 16 Jan 2008 00:24:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.joeberkovitz.com/blog/?p=47#comment-133</guid>
		<description>As Robert mentioned if you use strong references sometimes the object gets lost and you can never GC it.  This happened to me running a flex app that dispatched many events as part of a streaming bus between a server and the app.  As well as created and destroyed many widgets as part of a UI.  The problems   because the app needs to run for a long time.  The strong references somehow prevented the widgets from GC&#039;ing or barring that kept the even listeners around.  The end result was a totally bogged down flash app that ran 100% faster once all the listeners were replaced with weak versions.  That is all except those that would always need to be active.

So in short this is a godsend and I don&#039;t use strong references unless absolutely necessary. I can see how this will cause trouble in terms of the patterns described above but I think it worth mentioning that advising to use strong references whenever possible is not necessarily the right answer here.

My understanding of AS3 is still limited but from what I can tell I would suggest using weak references whenever possible, and be aware of the pitfalls.  The performance boost was amazing once I started using them.</description>
		<content:encoded><![CDATA[<p>As Robert mentioned if you use strong references sometimes the object gets lost and you can never GC it.  This happened to me running a flex app that dispatched many events as part of a streaming bus between a server and the app.  As well as created and destroyed many widgets as part of a UI.  The problems   because the app needs to run for a long time.  The strong references somehow prevented the widgets from GC&#8217;ing or barring that kept the even listeners around.  The end result was a totally bogged down flash app that ran 100% faster once all the listeners were replaced with weak versions.  That is all except those that would always need to be active.</p>
<p>So in short this is a godsend and I don&#8217;t use strong references unless absolutely necessary. I can see how this will cause trouble in terms of the patterns described above but I think it worth mentioning that advising to use strong references whenever possible is not necessarily the right answer here.</p>
<p>My understanding of AS3 is still limited but from what I can tell I would suggest using weak references whenever possible, and be aware of the pitfalls.  The performance boost was amazing once I started using them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Penner</title>
		<link>http://joeberkovitz.com/blog/2007/06/20/moment-of-weakness-weak-event-listeners-can-be-dangerous/comment-page-1/#comment-131</link>
		<dc:creator>Robert Penner</dc:creator>
		<pubDate>Wed, 21 Nov 2007 20:27:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.joeberkovitz.com/blog/?p=47#comment-131</guid>
		<description>&gt; Weak event listeners are great if the client that obtains them can be expected to maintain a reference to them for as long as they need live.

If you are not maintaining a reference to an object and thereby directly controlling how long it lives, then you are headed for one of two problems:

1) If you use a weak listener reference, the object will be garbage collected at a random time, as you describe.

2) If you DON&#039;T use a weak listener reference, you&#039;re setting yourself up for a memory leak. If the object falls out of scope and you no longer have a named reference to it, that means you have no way to release it to the garbage collector. There will be an unnamed reference to the object in a listeners array somewhere that will exist forever. That is, unless you have some scheme where the object removes itself as a listener. But if the object fails to do that, it will stick around.</description>
		<content:encoded><![CDATA[<p>&gt; Weak event listeners are great if the client that obtains them can be expected to maintain a reference to them for as long as they need live.</p>
<p>If you are not maintaining a reference to an object and thereby directly controlling how long it lives, then you are headed for one of two problems:</p>
<p>1) If you use a weak listener reference, the object will be garbage collected at a random time, as you describe.</p>
<p>2) If you DON&#8217;T use a weak listener reference, you&#8217;re setting yourself up for a memory leak. If the object falls out of scope and you no longer have a named reference to it, that means you have no way to release it to the garbage collector. There will be an unnamed reference to the object in a listeners array somewhere that will exist forever. That is, unless you have some scheme where the object removes itself as a listener. But if the object fails to do that, it will stick around.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Weak References: Utilisation potentiellement dangereuse. &#124; Matsiya</title>
		<link>http://joeberkovitz.com/blog/2007/06/20/moment-of-weakness-weak-event-listeners-can-be-dangerous/comment-page-1/#comment-130</link>
		<dc:creator>Weak References: Utilisation potentiellement dangereuse. &#124; Matsiya</dc:creator>
		<pubDate>Sat, 08 Sep 2007 15:50:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.joeberkovitz.com/blog/?p=47#comment-130</guid>
		<description>[...] L&#8217;article sur le blog de Joe Berkovitz : Moment of Weakness: Weak Event Listeners Can Be Dangerous [...]</description>
		<content:encoded><![CDATA[<p>[...] L&#38;#8217;article sur le blog de Joe Berkovitz : Moment of Weakness: Weak Event Listeners Can Be Dangerous [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Rangel</title>
		<link>http://joeberkovitz.com/blog/2007/06/20/moment-of-weakness-weak-event-listeners-can-be-dangerous/comment-page-1/#comment-129</link>
		<dc:creator>Paul Rangel</dc:creator>
		<pubDate>Sat, 11 Aug 2007 22:15:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.joeberkovitz.com/blog/?p=47#comment-129</guid>
		<description>Awesome and thanks again Joe. I owe you a pint at the next event!

paul</description>
		<content:encoded><![CDATA[<p>Awesome and thanks again Joe. I owe you a pint at the next event!</p>
<p>paul</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: joe</title>
		<link>http://joeberkovitz.com/blog/2007/06/20/moment-of-weakness-weak-event-listeners-can-be-dangerous/comment-page-1/#comment-128</link>
		<dc:creator>joe</dc:creator>
		<pubDate>Sat, 11 Aug 2007 19:10:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.joeberkovitz.com/blog/?p=47#comment-128</guid>
		<description>Paul, I don&#039;t see any problems off hand in the pattern.  There is nothing in the pattern that says weak listeners need to be used, and an Operation is a disposable object, so attaching strong listeners to it should be safe (they can be harvested once the Operation itself is GCed).  I try to avoid weak listeners anywhere unless there&#039;s some ironclad argument for them.

Did I miss something?  Let me know if you see a specific case.

As far as 360Flex in Seattle goes, my Allurent colleague Jim Echmalian (http://www.ech.net/blog/) will be speaking there about &quot;Practical Patterns in Flex&quot; which picks up where MVCS leaves off.  I highly, highly recommend seeing his talk!

--Joe</description>
		<content:encoded><![CDATA[<p>Paul, I don&#8217;t see any problems off hand in the pattern.  There is nothing in the pattern that says weak listeners need to be used, and an Operation is a disposable object, so attaching strong listeners to it should be safe (they can be harvested once the Operation itself is GCed).  I try to avoid weak listeners anywhere unless there&#8217;s some ironclad argument for them.</p>
<p>Did I miss something?  Let me know if you see a specific case.</p>
<p>As far as 360Flex in Seattle goes, my Allurent colleague Jim Echmalian (<a href="http://www.ech.net/blog/" rel="nofollow">http://www.ech.net/blog/</a>) will be speaking there about &#8220;Practical Patterns in Flex&#8221; which picks up where MVCS leaves off.  I highly, highly recommend seeing his talk!</p>
<p>&#8211;Joe</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Rangel</title>
		<link>http://joeberkovitz.com/blog/2007/06/20/moment-of-weakness-weak-event-listeners-can-be-dangerous/comment-page-1/#comment-127</link>
		<dc:creator>Paul Rangel</dc:creator>
		<pubDate>Sat, 11 Aug 2007 16:27:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.joeberkovitz.com/blog/?p=47#comment-127</guid>
		<description>We are avid users of the MVCS pattern you described on the Adobe website and I swear this has happened to us on occasion. Seems that the operation classes in the pattern would be victim. Do you see any potential pitfalls in the MVCS pattern for this bug?

Also, I was looking forward to your talk at Flex360 you going to be on the West Coast in the future? Thanks for the great tips and see ya at the next Flex event.

-paul</description>
		<content:encoded><![CDATA[<p>We are avid users of the MVCS pattern you described on the Adobe website and I swear this has happened to us on occasion. Seems that the operation classes in the pattern would be victim. Do you see any potential pitfalls in the MVCS pattern for this bug?</p>
<p>Also, I was looking forward to your talk at Flex360 you going to be on the West Coast in the future? Thanks for the great tips and see ya at the next Flex event.</p>
<p>-paul</p>
]]></content:encoded>
	</item>
</channel>
</rss>

