<?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: Asynchronous calls explained</title>
	<atom:link href="http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/feed/" rel="self" type="application/rss+xml" />
	<link>http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/</link>
	<description>music, technology, interfaces, people</description>
	<lastBuildDate>Tue, 03 Aug 2010 22:16:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Balint</title>
		<link>http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/comment-page-1/#comment-288585</link>
		<dc:creator>Balint</dc:creator>
		<pubDate>Thu, 02 Jul 2009 20:45:33 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/#comment-288585</guid>
		<description>Sho, pending variable is really needed in strategy 3?</description>
		<content:encoded><![CDATA[<p>Sho, pending variable is really needed in strategy 3?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fahad</title>
		<link>http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/comment-page-1/#comment-107430</link>
		<dc:creator>fahad</dc:creator>
		<pubDate>Tue, 18 Dec 2007 11:17:21 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/#comment-107430</guid>
		<description>hmm , well people .. i tried creating a bindable boolean that, if &#039;false&#039; will just waste the loop cycles and when the result method is executed .. its turned to a &#039;true&#039; value ... 
//**********************************************calling myltiple streams
while(stream.bytesAvailable)
if(flag == false)
continue;
else
{
//read
//send another request
}
//*************************on result of each stream

onresult()
{
//perform action

flag = true;
}
 

// it should work.. but i just tried it and flex builder hangs :D
// not to mention this is the simplest way !</description>
		<content:encoded><![CDATA[<p>hmm , well people .. i tried creating a bindable boolean that, if &#8216;false&#8217; will just waste the loop cycles and when the result method is executed .. its turned to a &#8216;true&#8217; value &#8230;<br />
//**********************************************calling myltiple streams<br />
while(stream.bytesAvailable)<br />
if(flag == false)<br />
continue;<br />
else<br />
{<br />
//read<br />
//send another request<br />
}<br />
//*************************on result of each stream</p>
<p>onresult()<br />
{<br />
//perform action</p>
<p>flag = true;<br />
}</p>
<p>// it should work.. but i just tried it and flex builder hangs :D<br />
// not to mention this is the simplest way !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Florecista&#8217;s Weblog</title>
		<link>http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/comment-page-1/#comment-55250</link>
		<dc:creator>Florecista&#8217;s Weblog</dc:creator>
		<pubDate>Mon, 10 Sep 2007 05:40:24 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/#comment-55250</guid>
		<description>[...] Asynchronous calls explained [...]</description>
		<content:encoded><![CDATA[<p>[...] Asynchronous calls explained [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hotfusion</title>
		<link>http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/comment-page-1/#comment-22549</link>
		<dc:creator>hotfusion</dc:creator>
		<pubDate>Wed, 02 May 2007 17:57:01 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/#comment-22549</guid>
		<description>Sorry, but the pre tag doesn&#039;t work for me! Could you please fix my last post?</description>
		<content:encoded><![CDATA[<p>Sorry, but the pre tag doesn&#8217;t work for me! Could you please fix my last post?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hotfusion</title>
		<link>http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/comment-page-1/#comment-22548</link>
		<dc:creator>hotfusion</dc:creator>
		<pubDate>Wed, 02 May 2007 17:55:19 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/#comment-22548</guid>
		<description>Nice article! I have been trying to figure this problem out for ages!

Here is my attempt to find out if a locally declared URLLoader with no other reference would persist.


// Count the no. of URLLoader created
var ldrACount:uint = 0
// Count the no. of URLLoader responses received
var ldrRCount:uint = 0;
function ldrGen(e:Event) {
	// Just create 100 instances (I don&#039;t want to hang the machine)
	if (ldrACount 


Here is the php script. It basically sends a no-cache header and a large amount of random data.




Here is a simple output that I am getting:

Total: 4 Received: 1
Total: 4 Received: 2
Total: 9 Received: 3
Total: 17 Received: 4
Total: 24 Received: 5
Total: 38 Received: 6
Total: 46 Received: 7
Total: 48 Received: 8
Total: 50 Received: 9
Total: 50 Received: 10
Total: 51 Received: 11
Total: 52 Received: 12
Total: 53 Received: 13
Total: 54 Received: 14
Total: 57 Received: 15
Total: 59 Received: 16
Total: 65 Received: 17
Total: 77 Received: 18
Total: 81 Received: 19
Total: 92 Received: 20
Total: 94 Received: 21
Total: 95 Received: 22
Total: 97 Received: 23
Total: 97 Received: 24
Total: 99 Received: 25
Total: 99 Received: 26
Total: 99 Received: 27
Total: 99 Received: 28
Total: 100 Received: 29
Total: 100 Received: 30
Total: 100 Received: 31
Total: 100 Received: 32
Total: 100 Received: 33
Total: 100 Received: 34
Total: 100 Received: 35
Total: 100 Received: 36
Total: 100 Received: 37
Total: 100 Received: 38
Total: 100 Received: 39
Total: 100 Received: 40
Total: 100 Received: 41
Total: 100 Received: 42
Total: 100 Received: 43
Total: 100 Received: 44
Total: 100 Received: 45
Total: 100 Received: 46
Total: 100 Received: 47
Total: 100 Received: 48
Total: 100 Received: 49
Total: 100 Received: 50
Total: 100 Received: 51
Total: 100 Received: 52
Total: 100 Received: 53
Total: 100 Received: 54
Total: 100 Received: 55
Total: 100 Received: 56
Total: 100 Received: 57
Total: 100 Received: 58
Total: 100 Received: 59
Total: 100 Received: 60
Total: 100 Received: 61
Total: 100 Received: 62
Total: 100 Received: 63
Total: 100 Received: 64
Total: 100 Received: 65
Total: 100 Received: 66
Total: 100 Received: 67
Total: 100 Received: 68
Total: 100 Received: 69
Total: 100 Received: 70
Total: 100 Received: 71
Total: 100 Received: 72
Total: 100 Received: 73
Total: 100 Received: 74
Total: 100 Received: 75
Total: 100 Received: 76
Total: 100 Received: 77
Total: 100 Received: 78
Total: 100 Received: 79
Total: 100 Received: 80
Total: 100 Received: 81
Total: 100 Received: 82
Total: 100 Received: 83
Total: 100 Received: 84
Total: 100 Received: 85
Total: 100 Received: 86
Total: 100 Received: 87
Total: 100 Received: 88
Total: 100 Received: 89
Total: 100 Received: 90
Total: 100 Received: 91
Total: 100 Received: 92
Total: 100 Received: 93
Total: 100 Received: 94
Total: 100 Received: 95
Total: 100 Received: 96
Total: 100 Received: 97
Total: 100 Received: 98
Total: 100 Received: 99
Total: 100 Received: 100


I am always receiving 100 response, and notice how I am still receiving responses when the total hit 100. I think it&#039;s a pretty good proof that active URLLoader is immune from garbage collection.

Any comment?</description>
		<content:encoded><![CDATA[<p>Nice article! I have been trying to figure this problem out for ages!</p>
<p>Here is my attempt to find out if a locally declared URLLoader with no other reference would persist.</p>
<p>// Count the no. of URLLoader created<br />
var ldrACount:uint = 0<br />
// Count the no. of URLLoader responses received<br />
var ldrRCount:uint = 0;<br />
function ldrGen(e:Event) {<br />
	// Just create 100 instances (I don&#8217;t want to hang the machine)<br />
	if (ldrACount </p>
<p>Here is the php script. It basically sends a no-cache header and a large amount of random data.</p>
<p>Here is a simple output that I am getting:</p>
<p>Total: 4 Received: 1<br />
Total: 4 Received: 2<br />
Total: 9 Received: 3<br />
Total: 17 Received: 4<br />
Total: 24 Received: 5<br />
Total: 38 Received: 6<br />
Total: 46 Received: 7<br />
Total: 48 Received: 8<br />
Total: 50 Received: 9<br />
Total: 50 Received: 10<br />
Total: 51 Received: 11<br />
Total: 52 Received: 12<br />
Total: 53 Received: 13<br />
Total: 54 Received: 14<br />
Total: 57 Received: 15<br />
Total: 59 Received: 16<br />
Total: 65 Received: 17<br />
Total: 77 Received: 18<br />
Total: 81 Received: 19<br />
Total: 92 Received: 20<br />
Total: 94 Received: 21<br />
Total: 95 Received: 22<br />
Total: 97 Received: 23<br />
Total: 97 Received: 24<br />
Total: 99 Received: 25<br />
Total: 99 Received: 26<br />
Total: 99 Received: 27<br />
Total: 99 Received: 28<br />
Total: 100 Received: 29<br />
Total: 100 Received: 30<br />
Total: 100 Received: 31<br />
Total: 100 Received: 32<br />
Total: 100 Received: 33<br />
Total: 100 Received: 34<br />
Total: 100 Received: 35<br />
Total: 100 Received: 36<br />
Total: 100 Received: 37<br />
Total: 100 Received: 38<br />
Total: 100 Received: 39<br />
Total: 100 Received: 40<br />
Total: 100 Received: 41<br />
Total: 100 Received: 42<br />
Total: 100 Received: 43<br />
Total: 100 Received: 44<br />
Total: 100 Received: 45<br />
Total: 100 Received: 46<br />
Total: 100 Received: 47<br />
Total: 100 Received: 48<br />
Total: 100 Received: 49<br />
Total: 100 Received: 50<br />
Total: 100 Received: 51<br />
Total: 100 Received: 52<br />
Total: 100 Received: 53<br />
Total: 100 Received: 54<br />
Total: 100 Received: 55<br />
Total: 100 Received: 56<br />
Total: 100 Received: 57<br />
Total: 100 Received: 58<br />
Total: 100 Received: 59<br />
Total: 100 Received: 60<br />
Total: 100 Received: 61<br />
Total: 100 Received: 62<br />
Total: 100 Received: 63<br />
Total: 100 Received: 64<br />
Total: 100 Received: 65<br />
Total: 100 Received: 66<br />
Total: 100 Received: 67<br />
Total: 100 Received: 68<br />
Total: 100 Received: 69<br />
Total: 100 Received: 70<br />
Total: 100 Received: 71<br />
Total: 100 Received: 72<br />
Total: 100 Received: 73<br />
Total: 100 Received: 74<br />
Total: 100 Received: 75<br />
Total: 100 Received: 76<br />
Total: 100 Received: 77<br />
Total: 100 Received: 78<br />
Total: 100 Received: 79<br />
Total: 100 Received: 80<br />
Total: 100 Received: 81<br />
Total: 100 Received: 82<br />
Total: 100 Received: 83<br />
Total: 100 Received: 84<br />
Total: 100 Received: 85<br />
Total: 100 Received: 86<br />
Total: 100 Received: 87<br />
Total: 100 Received: 88<br />
Total: 100 Received: 89<br />
Total: 100 Received: 90<br />
Total: 100 Received: 91<br />
Total: 100 Received: 92<br />
Total: 100 Received: 93<br />
Total: 100 Received: 94<br />
Total: 100 Received: 95<br />
Total: 100 Received: 96<br />
Total: 100 Received: 97<br />
Total: 100 Received: 98<br />
Total: 100 Received: 99<br />
Total: 100 Received: 100</p>
<p>I am always receiving 100 response, and notice how I am still receiving responses when the total hit 100. I think it&#8217;s a pretty good proof that active URLLoader is immune from garbage collection.</p>
<p>Any comment?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sho</title>
		<link>http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/comment-page-1/#comment-21504</link>
		<dc:creator>sho</dc:creator>
		<pubDate>Thu, 26 Apr 2007 23:29:39 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/#comment-21504</guid>
		<description>Fixed it. Use the &lt;pre&gt; tag for code. 

Thanks for all the research on this issue!</description>
		<content:encoded><![CDATA[<p>Fixed it. Use the &lt;pre&gt; tag for code. </p>
<p>Thanks for all the research on this issue!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ray Greenwell</title>
		<link>http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/comment-page-1/#comment-21502</link>
		<dc:creator>Ray Greenwell</dc:creator>
		<pubDate>Thu, 26 Apr 2007 23:21:10 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/#comment-21502</guid>
		<description>Sho: sure, delete #18. How did you embed the code? Which tag do I use?

It seems also that the code in genCrap() got a little mangled.

&lt;pre&gt;
    public static function genCrap (crap :Array) :void
    {
        for (var ii :int = 0; ii &lt; 10000; ii++) {
            var s :String = &quot;&quot;;
            for (var jj :int = 100; jj &gt;= 0; jj--) {
                s += String.fromCharCode(int(Math.random() * 26) + 65);
            }
            crap.push(s);
        }
    }
&lt;/pre&gt;

And: you&#039;re right. In the above test, the &#039;theBlackHole&#039; function seems to get ENTER_FRAME events until the end of time.

Perhaps the case I was seeing before was because content loaded into a different application domain can be gc&#039;d if unloaded? I would like to perform some more tests but am holding off right now because I have real work to do.</description>
		<content:encoded><![CDATA[<p>Sho: sure, delete #18. How did you embed the code? Which tag do I use?</p>
<p>It seems also that the code in genCrap() got a little mangled.</p>
<pre>
    public static function genCrap (crap :Array) :void
    {
        for (var ii :int = 0; ii &lt; 10000; ii++) {
            var s :String = "";
            for (var jj :int = 100; jj &gt;= 0; jj--) {
                s += String.fromCharCode(int(Math.random() * 26) + 65);
            }
            crap.push(s);
        }
    }
</pre>
<p>And: you&#8217;re right. In the above test, the &#8216;theBlackHole&#8217; function seems to get ENTER_FRAME events until the end of time.</p>
<p>Perhaps the case I was seeing before was because content loaded into a different application domain can be gc&#8217;d if unloaded? I would like to perform some more tests but am holding off right now because I have real work to do.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sho</title>
		<link>http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/comment-page-1/#comment-21500</link>
		<dc:creator>sho</dc:creator>
		<pubDate>Thu, 26 Apr 2007 22:44:49 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/#comment-21500</guid>
		<description>I fixed it for you, Ray. Do you want me to delete comment #18?

Great work on figuring out the ENTER_FRAME event listener issue. That is almost certainly the reason these items were not being garbage collected.

It&#039;s puzzling to me that a sprite would get a couple ENTER_FRAME events after being removed from the display list. It seems like either it should continue to get them forever, or it should stop getting them as soon as they were no longer on the display list. Hmm..

-Sho</description>
		<content:encoded><![CDATA[<p>I fixed it for you, Ray. Do you want me to delete comment #18?</p>
<p>Great work on figuring out the ENTER_FRAME event listener issue. That is almost certainly the reason these items were not being garbage collected.</p>
<p>It&#8217;s puzzling to me that a sprite would get a couple ENTER_FRAME events after being removed from the display list. It seems like either it should continue to get them forever, or it should stop getting them as soon as they were no longer on the display list. Hmm..</p>
<p>-Sho</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ray Greenwell</title>
		<link>http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/comment-page-1/#comment-21481</link>
		<dc:creator>Ray Greenwell</dc:creator>
		<pubDate>Thu, 26 Apr 2007 21:06:05 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/#comment-21481</guid>
		<description>Dang it. How do I post code to wordpress? I looked in the docs and they said &lt;code&gt; and &lt;pre&gt; were the way to go, but they didn&#039;t work for me.</description>
		<content:encoded><![CDATA[<p>Dang it. How do I post code to wordpress? I looked in the docs and they said &lt;code&gt; and &lt;pre&gt; were the way to go, but they didn&#8217;t work for me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ray Greenwell</title>
		<link>http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/comment-page-1/#comment-21477</link>
		<dc:creator>Ray Greenwell</dc:creator>
		<pubDate>Thu, 26 Apr 2007 21:03:05 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/2007/04/25/asynchronous-calls-explained/#comment-21477</guid>
		<description>Sho,

I&#039;ve learned some more.

Here&#039;s my test program:

&lt;pre&gt;package {

import flash.display.Sprite;

import flash.events.Event;
import flash.events.MouseEvent;

import flash.text.TextField;

import flash.system.System;

[SWF(width=&quot;500&quot;, height=&quot;500&quot;)]
public class GarbageTest extends Sprite
{
    public function GarbageTest ()
    {
        addEventListener(Event.ENTER_FRAME, handleFrame);

        _tf = new TextField();
        _tf.background = true;
        _tf.multiline = true;
        _tf.width = 500;
        _tf.height = 500;
        addChild(_tf);

        _removeListener = (Math.random() &gt;= .5);
        _event = (Math.random() &gt;= .5) ? Event.ENTER_FRAME : MouseEvent.CLICK;
        _tf.appendText(&quot;Will &quot; + (_removeListener ? &quot;&quot; : &quot;NOT &quot;) +
            &quot;remove &#039;&quot; + _event + &quot;&#039; listener...&quot;);
    }

    protected function handleFrame (... ignored) :void
    {
        _frameCount++;
        switch (_frameCount) {
        case 30:
            _tf.appendText(&quot;\n\nBefore creation: &quot; + memUsage());
            _otherSprite = new Other();
            _otherSprite.addEventListener(_event, theBlackHole);
            break;

        case 31:
            _tf.appendText(&quot;\nCreated big sprite: &quot; + memUsage());
            break;

        case 60:
            if (_removeListener) {
                _otherSprite.removeEventListener(_event, theBlackHole);
            }
            _otherSprite = null;
            _tf.appendText(&quot;\nNulled sprite: &quot; + memUsage());
            break;

        case 90:
            genCrap(new Array());
            _tf.appendText(&quot;\nGenerated more objects and immediately tossed: &quot; +
                memUsage());
            break;

        case 120:
            _tf.appendText(&quot;\nFinally... &quot; + memUsage());
            break;

        case 150:
            _tf.appendText(&quot;\n\nReload to try again.&quot;);
            break;
        }
    }

    protected function memUsage () :String
    {
        return String(int(System.totalMemory / (1024 * 1024))) + &quot;MB&quot;;
    }

    public function theBlackHole (... ignored) :void
    {
        trace(&quot;What are you doing in here?&quot;);
    }

    public static function genCrap (crap :Array) :void
    {
        for (var ii :int = 0; ii &lt; 10000; ii++) {
            var s :String = &quot;&quot;;
            for (var jj :int = 100; jj &gt;= 0; jj--) {
                s += String.fromCharCode(int(Math.random() * 26) + 65);
            }
            crap.push(s);
        }
    }

    protected var _removeListener :Boolean;

    protected var _otherSprite :Other;

    protected var _frameCount :int = 0;

    protected var _tf :TextField;

    protected var _event :String;
}
}

import flash.display.Sprite;

import flash.events.Event;
import flash.events.EventDispatcher;

class Other extends Sprite
{   
    public function Other ()
    {
        GarbageTest.genCrap(_crap);
    }

    protected var _crap :Array = [];
}
&lt;/pre&gt;

Running that swf picks two things at random: whether to listen for MouseEvent.CLICK or Event.ENTER_FRAME, and whether to remove the listener or not. The program does a few things and prints memory usage, and at the end the &quot;Finally...&quot; text should print a memory usage similar to what it was at the start of the program.

What I&#039;m observing is that the sprite is kept around if there is an ENTER_FRAME listener registered on it, but other events do not do this.

I have a theory as to why this is. I&#039;ve noticed in the past that ENTER_FRAME will be dispatched to a display object even after that object is removed from the hierarchy. I just now noticed that the documentation for ENTER_FRAME on DisplayObject states: &lt;code&gt;Note: This event does not go through a &quot;capture phase&quot; and is dispatched directly to the target, whether the target is on the display list or not.&lt;/code&gt; Probably ENTER_FRAME is such an important event that there is an optimization internally in the player to quick-dispatch the event.

Maybe that is what is preventing the garbage collection.

In the past I had noticed that while a Sprite may get ENTER_FRAME a few more times after being removed from the display list, it seemed to stop after a second or two. Now I wonder if that means that Sprite is still in memory, but the ENTER_FRAME system just finally noticed that it&#039;s off the list.

I wonder if there are any other event types that cause this behavior?</description>
		<content:encoded><![CDATA[<p>Sho,</p>
<p>I&#8217;ve learned some more.</p>
<p>Here&#8217;s my test program:</p>
<pre>package {

import flash.display.Sprite;

import flash.events.Event;
import flash.events.MouseEvent;

import flash.text.TextField;

import flash.system.System;

[SWF(width="500", height="500")]
public class GarbageTest extends Sprite
{
    public function GarbageTest ()
    {
        addEventListener(Event.ENTER_FRAME, handleFrame);

        _tf = new TextField();
        _tf.background = true;
        _tf.multiline = true;
        _tf.width = 500;
        _tf.height = 500;
        addChild(_tf);

        _removeListener = (Math.random() &gt;= .5);
        _event = (Math.random() &gt;= .5) ? Event.ENTER_FRAME : MouseEvent.CLICK;
        _tf.appendText("Will " + (_removeListener ? "" : "NOT ") +
            "remove '" + _event + "' listener...");
    }

    protected function handleFrame (... ignored) :void
    {
        _frameCount++;
        switch (_frameCount) {
        case 30:
            _tf.appendText("\n\nBefore creation: " + memUsage());
            _otherSprite = new Other();
            _otherSprite.addEventListener(_event, theBlackHole);
            break;

        case 31:
            _tf.appendText("\nCreated big sprite: " + memUsage());
            break;

        case 60:
            if (_removeListener) {
                _otherSprite.removeEventListener(_event, theBlackHole);
            }
            _otherSprite = null;
            _tf.appendText("\nNulled sprite: " + memUsage());
            break;

        case 90:
            genCrap(new Array());
            _tf.appendText("\nGenerated more objects and immediately tossed: " +
                memUsage());
            break;

        case 120:
            _tf.appendText("\nFinally... " + memUsage());
            break;

        case 150:
            _tf.appendText("\n\nReload to try again.");
            break;
        }
    }

    protected function memUsage () :String
    {
        return String(int(System.totalMemory / (1024 * 1024))) + "MB";
    }

    public function theBlackHole (... ignored) :void
    {
        trace("What are you doing in here?");
    }

    public static function genCrap (crap :Array) :void
    {
        for (var ii :int = 0; ii &lt; 10000; ii++) {
            var s :String = "";
            for (var jj :int = 100; jj &gt;= 0; jj--) {
                s += String.fromCharCode(int(Math.random() * 26) + 65);
            }
            crap.push(s);
        }
    }

    protected var _removeListener :Boolean;

    protected var _otherSprite :Other;

    protected var _frameCount :int = 0;

    protected var _tf :TextField;

    protected var _event :String;
}
}

import flash.display.Sprite;

import flash.events.Event;
import flash.events.EventDispatcher;

class Other extends Sprite
{
    public function Other ()
    {
        GarbageTest.genCrap(_crap);
    }

    protected var _crap :Array = [];
}
</pre>
<p>Running that swf picks two things at random: whether to listen for MouseEvent.CLICK or Event.ENTER_FRAME, and whether to remove the listener or not. The program does a few things and prints memory usage, and at the end the &#8220;Finally&#8230;&#8221; text should print a memory usage similar to what it was at the start of the program.</p>
<p>What I&#8217;m observing is that the sprite is kept around if there is an ENTER_FRAME listener registered on it, but other events do not do this.</p>
<p>I have a theory as to why this is. I&#8217;ve noticed in the past that ENTER_FRAME will be dispatched to a display object even after that object is removed from the hierarchy. I just now noticed that the documentation for ENTER_FRAME on DisplayObject states: <code>Note: This event does not go through a "capture phase" and is dispatched directly to the target, whether the target is on the display list or not.</code> Probably ENTER_FRAME is such an important event that there is an optimization internally in the player to quick-dispatch the event.</p>
<p>Maybe that is what is preventing the garbage collection.</p>
<p>In the past I had noticed that while a Sprite may get ENTER_FRAME a few more times after being removed from the display list, it seemed to stop after a second or two. Now I wonder if that means that Sprite is still in memory, but the ENTER_FRAME system just finally noticed that it&#8217;s off the list.</p>
<p>I wonder if there are any other event types that cause this behavior?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
