<?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: AS3 Garbage Collection, the reason your tweens are ending early.</title>
	<atom:link href="http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/</link>
	<description>Calgary Flash and Flex Developer</description>
	<lastBuildDate>Sat, 14 Jan 2012 02:54:06 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Jim</title>
		<link>http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/comment-page-1/#comment-1570</link>
		<dc:creator>Jim</dc:creator>
		<pubDate>Wed, 05 Jan 2011 06:20:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/#comment-1570</guid>
		<description>Thank you so much!  I was about to completely give up on the whole project, and this article pulled me back from the brink of despair</description>
		<content:encoded><![CDATA[<p>Thank you so much!  I was about to completely give up on the whole project, and this article pulled me back from the brink of despair</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tanja</title>
		<link>http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/comment-page-1/#comment-1562</link>
		<dc:creator>Tanja</dc:creator>
		<pubDate>Sun, 21 Nov 2010 14:01:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/#comment-1562</guid>
		<description>Thanks a lot!!!!!</description>
		<content:encoded><![CDATA[<p>Thanks a lot!!!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Olivier Lamontagne</title>
		<link>http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/comment-page-1/#comment-1518</link>
		<dc:creator>Olivier Lamontagne</dc:creator>
		<pubDate>Thu, 12 Aug 2010 20:00:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/#comment-1518</guid>
		<description>I just had this problem at a very unfortunate moment, a 36h game-development marathon... I had to make my custom cheap tween with an ENTER_FRAME event... -_-

Now I feel stupid not having thought of it before :P</description>
		<content:encoded><![CDATA[<p>I just had this problem at a very unfortunate moment, a 36h game-development marathon&#8230; I had to make my custom cheap tween with an ENTER_FRAME event&#8230; -_-</p>
<p>Now I feel stupid not having thought of it before <img src='http://www.scottgmorgan.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Amy</title>
		<link>http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/comment-page-1/#comment-1516</link>
		<dc:creator>Amy</dc:creator>
		<pubDate>Mon, 02 Aug 2010 13:45:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/#comment-1516</guid>
		<description>I agree with Marcus.  Adding the eventListener in and of itself will prevent an EventDispatcher from being garbage collected, unless you use weak references.  That is what the weak reference flag is there for.

Instead, I think that the Class that is adding the listeners is itself being garbage collected.  I would suspect that, around the time you added hard references to the tweens, you also added a hard reference to this data class that is instantiating them, thus preventing it from being garbage collected, along with the tweens it references.</description>
		<content:encoded><![CDATA[<p>I agree with Marcus.  Adding the eventListener in and of itself will prevent an EventDispatcher from being garbage collected, unless you use weak references.  That is what the weak reference flag is there for.</p>
<p>Instead, I think that the Class that is adding the listeners is itself being garbage collected.  I would suspect that, around the time you added hard references to the tweens, you also added a hard reference to this data class that is instantiating them, thus preventing it from being garbage collected, along with the tweens it references.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marc</title>
		<link>http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/comment-page-1/#comment-1515</link>
		<dc:creator>Marc</dc:creator>
		<pubDate>Wed, 28 Jul 2010 14:25:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/#comment-1515</guid>
		<description>Matty&#039;s solution seems to work, and personally I&#039;m for the simplest answer. The other solutions may indeed work, but are way too complicated to understand or apply.

Thanks everyone, especially Matty.</description>
		<content:encoded><![CDATA[<p>Matty&#8217;s solution seems to work, and personally I&#8217;m for the simplest answer. The other solutions may indeed work, but are way too complicated to understand or apply.</p>
<p>Thanks everyone, especially Matty.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Isak</title>
		<link>http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/comment-page-1/#comment-1504</link>
		<dc:creator>Isak</dc:creator>
		<pubDate>Wed, 02 Jun 2010 07:46:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/#comment-1504</guid>
		<description>Thank you.</description>
		<content:encoded><![CDATA[<p>Thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel</title>
		<link>http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/comment-page-1/#comment-1503</link>
		<dc:creator>Daniel</dc:creator>
		<pubDate>Fri, 28 May 2010 11:53:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/#comment-1503</guid>
		<description>Thanks! This tween thing nearly drove me crazy.</description>
		<content:encoded><![CDATA[<p>Thanks! This tween thing nearly drove me crazy.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: foobar</title>
		<link>http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/comment-page-1/#comment-1501</link>
		<dc:creator>foobar</dc:creator>
		<pubDate>Wed, 05 May 2010 16:09:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/#comment-1501</guid>
		<description>i think you should update your post. &#039;cause Matty&#039;s right. You just need to create an var foo:Tween; global. Much quicker than your posted Workaround. And not everybody is going to read all the comments.</description>
		<content:encoded><![CDATA[<p>i think you should update your post. &#8217;cause Matty&#8217;s right. You just need to create an var foo:Tween; global. Much quicker than your posted Workaround. And not everybody is going to read all the comments.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: frncescomm</title>
		<link>http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/comment-page-1/#comment-1500</link>
		<dc:creator>frncescomm</dc:creator>
		<pubDate>Mon, 03 May 2010 17:42:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/#comment-1500</guid>
		<description>Just forgot to say I still like other cleaner solutions better than keeping track of all tweens, with this class.

For instance saving the tweens inside the instances you are moving.
Just as an example (untested code):

public class MoveMe extends MovieClip {
     public var myTween1;
     ...
}
var aMoveMeInst:MoveMe=new MoveMe()

aMoveMeInst.myTween1=new Tween(aMoveMeInst,...

This way, if you have 100 sprites, each will keep its own Tween (or tweens if more) untill the sprite itself gets GC.

Thanks again,

Francesco</description>
		<content:encoded><![CDATA[<p>Just forgot to say I still like other cleaner solutions better than keeping track of all tweens, with this class.</p>
<p>For instance saving the tweens inside the instances you are moving.<br />
Just as an example (untested code):</p>
<p>public class MoveMe extends MovieClip {<br />
     public var myTween1;<br />
     &#8230;<br />
}<br />
var aMoveMeInst:MoveMe=new MoveMe()</p>
<p>aMoveMeInst.myTween1=new Tween(aMoveMeInst,&#8230;</p>
<p>This way, if you have 100 sprites, each will keep its own Tween (or tweens if more) untill the sprite itself gets GC.</p>
<p>Thanks again,</p>
<p>Francesco</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: frncescomm</title>
		<link>http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/comment-page-1/#comment-1499</link>
		<dc:creator>frncescomm</dc:creator>
		<pubDate>Mon, 03 May 2010 17:34:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottgmorgan.com/blog/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/#comment-1499</guid>
		<description>Thanks Scott for your idea.
Thanks Kevin for your solution.

I repackaged as a class with static methods so you can just call

TweenKeeper.keep(new Tween(...))

from everywhere, without worries. I still wonder why AS3 isn&#039;t taking care of this, or why AS3 help/examples on the Tween class, all use it the wrong way.



// Usage: TweenKeeper.keep(new Tween(this,&quot;shownPerc&quot;,Regular.easeInOut,this.shownPerc,1.0,40,false));

package  {
	import fl.transitions.Tween;
	import fl.transitions.TweenEvent;
	import flash.utils.Dictionary;
	
	public class TweenKeeper {
		protected static var antiGC:Dictionary = new Dictionary(false);

		public static function keep(t:Tween) {
			t.addEventListener(TweenEvent.MOTION_FINISH, tweenFinished);
			antiGC[t] = t;
		}
		static function tweenFinished(e:TweenEvent){
			antiGC[e.currentTarget] = null;
			delete antiGC[e.currentTarget];
		}
	}
}</description>
		<content:encoded><![CDATA[<p>Thanks Scott for your idea.<br />
Thanks Kevin for your solution.</p>
<p>I repackaged as a class with static methods so you can just call</p>
<p>TweenKeeper.keep(new Tween(&#8230;))</p>
<p>from everywhere, without worries. I still wonder why AS3 isn&#8217;t taking care of this, or why AS3 help/examples on the Tween class, all use it the wrong way.</p>
<p>// Usage: TweenKeeper.keep(new Tween(this,&#8221;shownPerc&#8221;,Regular.easeInOut,this.shownPerc,1.0,40,false));</p>
<p>package  {<br />
	import fl.transitions.Tween;<br />
	import fl.transitions.TweenEvent;<br />
	import flash.utils.Dictionary;</p>
<p>	public class TweenKeeper {<br />
		protected static var antiGC:Dictionary = new Dictionary(false);</p>
<p>		public static function keep(t:Tween) {<br />
			t.addEventListener(TweenEvent.MOTION_FINISH, tweenFinished);<br />
			antiGC[t] = t;<br />
		}<br />
		static function tweenFinished(e:TweenEvent){<br />
			antiGC[e.currentTarget] = null;<br />
			delete antiGC[e.currentTarget];<br />
		}<br />
	}<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>

