<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Anna Filina &#187; listeners</title>
	<atom:link href="http://annafilina.com/blog/tag/listeners/feed/" rel="self" type="application/rss+xml" />
	<link>http://annafilina.com/blog</link>
	<description>I fix stuff</description>
	<lastBuildDate>Wed, 04 Jan 2012 14:56:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Weak Event Listeners Warning</title>
		<link>http://annafilina.com/blog/weak-event-listeners-warning/</link>
		<comments>http://annafilina.com/blog/weak-event-listeners-warning/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 22:15:53 +0000</pubDate>
		<dc:creator>Anna</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[garbage collection]]></category>
		<category><![CDATA[listeners]]></category>

		<guid isPermaLink="false">http://annafilina.com/blog/?p=122</guid>
		<description><![CDATA[An object that has no references to it will be eventually garbage-collected. An event listener is also a reference, thus preventing it from being removed from memory.
In order to allow your objects to be garbage-collected, you can either remove all listeners from it or use weak event listeners instead (don&#8217;t forget to remove other references<div><a href="http://annafilina.com/blog/weak-event-listeners-warning/">Read the rest...</a></div><br />]]></description>
			<content:encoded><![CDATA[<p>An object that has no references to it will be eventually <a href="http://www.adobe.com/devnet/flashplayer/articles/garbage_collection.html">garbage-collected</a>. An event listener is also a reference, thus preventing it from being removed from memory.</p>
<p>In order to allow your objects to be garbage-collected, you can either remove all listeners from it or use weak event listeners instead (don&#8217;t forget to remove other references to it as well). To make a listener weak, you must set the 5th parameter  of the addEventListener method to true, like this:</p>
<pre class="brush:as3">var btn:Button = new Button();
btn.addEventListener(MouseEvent.CLICK, clickHandler, false, 0, true);</pre>
<p>But you have to be very careful where you use weak event listeners. When you instantiate an object in a function&#8217;s scope and then add weak event listeners, your object could be garbage-collected before it had a chance to dispatch these events. Example:</p>
<pre class="brush:as3">private function getStuff():void {
    var service:HTTPService = new HTTPService();
    service.url = "get-stuff.php";
    service.addEventListener(ResultEvent.RESULT, resultHandler, false, 0, true);
}</pre>
<p>In this case, you should either avoid using weak listeners and remove them manually, or add a reference to your object outside of the function&#8217;s scope to prevent it from being garbage-collected too early.</p>
]]></content:encoded>
			<wfw:commentRss>http://annafilina.com/blog/weak-event-listeners-warning/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

