<?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: Memory Leak in AS3 Loader Class</title>
	<atom:link href="http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/</link>
	<description>There is no universally agreed-upon biological definition of dreaming</description>
	<lastBuildDate>Fri, 21 Oct 2011 17:05:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: HildaMattson</title>
		<link>http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/comment-page-1/#comment-1169</link>
		<dc:creator>HildaMattson</dc:creator>
		<pubDate>Mon, 18 Apr 2011 16:32:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/#comment-1169</guid>
		<description>Enter comment here.</description>
		<content:encoded><![CDATA[<p>Enter comment here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: coder</title>
		<link>http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/comment-page-1/#comment-1111</link>
		<dc:creator>coder</dc:creator>
		<pubDate>Sun, 06 Jun 2010 20:44:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/#comment-1111</guid>
		<description>you may set a variable in the complete listener that stores the bitmap and then destroy the object later

public function COMPLETEListener(e:Event){
myBitmap = e.target.loader.content;
}

public function destroy(){
if(myBitmap is Bitmap){
						myBitmap.bitmapData.dispose(); 
	}
}

works fine for me load some big image and see the difference in the taskmanager</description>
		<content:encoded><![CDATA[<p>you may set a variable in the complete listener that stores the bitmap and then destroy the object later</p>
<p>public function COMPLETEListener(e:Event){<br />
myBitmap = e.target.loader.content;<br />
}</p>
<p>public function destroy(){<br />
if(myBitmap is Bitmap){<br />
						myBitmap.bitmapData.dispose();<br />
	}<br />
}</p>
<p>works fine for me load some big image and see the difference in the taskmanager</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: patCRUZ</title>
		<link>http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/comment-page-1/#comment-1080</link>
		<dc:creator>patCRUZ</dc:creator>
		<pubDate>Tue, 23 Feb 2010 16:27:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/#comment-1080</guid>
		<description>xpto.unloadAndStop();

should work! ;)</description>
		<content:encoded><![CDATA[<p>xpto.unloadAndStop();</p>
<p>should work! <img src='http://www.dreaminginflash.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harp</title>
		<link>http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/comment-page-1/#comment-961</link>
		<dc:creator>Harp</dc:creator>
		<pubDate>Tue, 02 Jun 2009 21:00:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/#comment-961</guid>
		<description>Great thread...can anyone perhaps tell me what needs to reside in this code below that will check for and remove a loaded clip, before loading a new one? I simply need to &quot;juggle&quot; swf files without the memory usage just going up indefinitely but can&#039;t seem to get it right. Thx.

var loader:Loader = new Loader();
addChildAt(loader,1);

btn1.addEventListener(MouseEvent.CLICK, getFile);
btn2.addEventListener(MouseEvent.CLICK, getFile);

btn1.dispatchEvent(new MouseEvent(MouseEvent.CLICK)); //loads first file

function getFile(e:MouseEvent):void {
    removeChild(loader);
	addChildAt(loader,1);
	var file = &quot;mc&quot; + e.target.name.substr(3) + &quot;.swf&quot;;
    loader.load(new URLRequest(file));

    var mem:String = Number( System.totalMemory / 1024 / 1024 ).toFixed( 2 ) + &#039;Mb&#039;;
    trace( mem );   
}</description>
		<content:encoded><![CDATA[<p>Great thread&#8230;can anyone perhaps tell me what needs to reside in this code below that will check for and remove a loaded clip, before loading a new one? I simply need to &#8220;juggle&#8221; swf files without the memory usage just going up indefinitely but can&#8217;t seem to get it right. Thx.</p>
<p>var loader:Loader = new Loader();<br />
addChildAt(loader,1);</p>
<p>btn1.addEventListener(MouseEvent.CLICK, getFile);<br />
btn2.addEventListener(MouseEvent.CLICK, getFile);</p>
<p>btn1.dispatchEvent(new MouseEvent(MouseEvent.CLICK)); //loads first file</p>
<p>function getFile(e:MouseEvent):void {<br />
    removeChild(loader);<br />
	addChildAt(loader,1);<br />
	var file = &#8220;mc&#8221; + e.target.name.substr(3) + &#8220;.swf&#8221;;<br />
    loader.load(new URLRequest(file));</p>
<p>    var mem:String = Number( System.totalMemory / 1024 / 1024 ).toFixed( 2 ) + &#8216;Mb&#8217;;<br />
    trace( mem );<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: luisM</title>
		<link>http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/comment-page-1/#comment-811</link>
		<dc:creator>luisM</dc:creator>
		<pubDate>Sun, 15 Feb 2009 18:22:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/#comment-811</guid>
		<description>i found some issues,   please remove  _index var and replace _loader[_index] for _loader.push, and ,  if ( _total == _index) for if ( _total == _loader.length )

sorry

LM :)</description>
		<content:encoded><![CDATA[<p>i found some issues,   please remove  _index var and replace _loader[_index] for _loader.push, and ,  if ( _total == _index) for if ( _total == _loader.length )</p>
<p>sorry</p>
<p>LM <img src='http://www.dreaminginflash.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: luisM</title>
		<link>http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/comment-page-1/#comment-810</link>
		<dc:creator>luisM</dc:creator>
		<pubDate>Sun, 15 Feb 2009 18:15:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/#comment-810</guid>
		<description>hi guys , very interesting  ,  i just wanted to check this out and wrote this code :

package {
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;

	public class memory extends Sprite
	{
		private var _loader:Array = new Array();
		
		private var _index:int;
		private var _total:int = 100;
		
		public function memory()
		{
			SimpleButton(this[&quot;btn2&quot;]).addEventListener(MouseEvent.CLICK, loadImg);		
		}
		
		protected function loadImg(ev:MouseEvent):void
		{
			var loader:Loader = new Loader();
			
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
			
			loader.load(new URLRequest(&quot;bg_equipo.png&quot;));
		}
		
		protected function onComplete(ev:Event):void
		{
			LoaderInfo(ev.target).removeEventListener(Event.COMPLETE, onComplete);
			_loader[_index] = Loader(addChild(LoaderInfo(ev.target).loader));
			
			_index++;
			
			if ( _total == _index)
			{
				SimpleButton(this[&quot;btn1&quot;]).addEventListener(MouseEvent.CLICK, onClick);
				trace(&quot;FINISHED !! &quot;);
			}
			else
				loadImg(null);			
		}
		
		protected function onClick(ev:MouseEvent):void
		{
			SimpleButton(this[&quot;btn1&quot;]).removeEventListener(MouseEvent.CLICK, onClick);			

			var len:int = _loader.length;
			for ( var i:int ; i &lt; len ; i++ )
			{
				var l:Loader = Loader(_loader.pop());
				if(l.contentLoaderInfo.childAllowsParent &amp;&amp; l.contentLoaderInfo.content is Bitmap){
					(l.contentLoaderInfo.content as Bitmap).bitmapData.dispose(); // remove bitmap from memory
				}

				l.unload();
				removeChild(l);
				l = null;
			}
			
			_loader = null;
			_loader = new Array();
		}
	}
}

to compile it create a fla file with this class as documentClass and to simpleButtons called btn1 and btn2 ,  and change the file name.

i load the same image  100 times and try the method i found here,  i&#039;m working on a macbook pro and in the  activity monitor i checked that the memory for the firefox goes up  in about 130 Mb, and when the clean method is executed the memory goes down about 50 MB, and it stays there.  the whole memory is not cleaned.

if someone finds code errors please let me know .   this issue is affecting my projects.

bye 

LM :)</description>
		<content:encoded><![CDATA[<p>hi guys , very interesting  ,  i just wanted to check this out and wrote this code :</p>
<p>package {<br />
	import flash.display.Bitmap;<br />
	import flash.display.Loader;<br />
	import flash.display.LoaderInfo;<br />
	import flash.display.SimpleButton;<br />
	import flash.display.Sprite;<br />
	import flash.events.Event;<br />
	import flash.events.MouseEvent;<br />
	import flash.net.URLRequest;</p>
<p>	public class memory extends Sprite<br />
	{<br />
		private var _loader:Array = new Array();</p>
<p>		private var _index:int;<br />
		private var _total:int = 100;</p>
<p>		public function memory()<br />
		{<br />
			SimpleButton(this["btn2"]).addEventListener(MouseEvent.CLICK, loadImg);<br />
		}</p>
<p>		protected function loadImg(ev:MouseEvent):void<br />
		{<br />
			var loader:Loader = new Loader();</p>
<p>			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);</p>
<p>			loader.load(new URLRequest(&#8220;bg_equipo.png&#8221;));<br />
		}</p>
<p>		protected function onComplete(ev:Event):void<br />
		{<br />
			LoaderInfo(ev.target).removeEventListener(Event.COMPLETE, onComplete);<br />
			_loader[_index] = Loader(addChild(LoaderInfo(ev.target).loader));</p>
<p>			_index++;</p>
<p>			if ( _total == _index)<br />
			{<br />
				SimpleButton(this["btn1"]).addEventListener(MouseEvent.CLICK, onClick);<br />
				trace(&#8220;FINISHED !! &#8220;);<br />
			}<br />
			else<br />
				loadImg(null);<br />
		}</p>
<p>		protected function onClick(ev:MouseEvent):void<br />
		{<br />
			SimpleButton(this["btn1"]).removeEventListener(MouseEvent.CLICK, onClick);			</p>
<p>			var len:int = _loader.length;<br />
			for ( var i:int ; i &lt; len ; i++ )<br />
			{<br />
				var l:Loader = Loader(_loader.pop());<br />
				if(l.contentLoaderInfo.childAllowsParent &amp;&amp; l.contentLoaderInfo.content is Bitmap){<br />
					(l.contentLoaderInfo.content as Bitmap).bitmapData.dispose(); // remove bitmap from memory<br />
				}</p>
<p>				l.unload();<br />
				removeChild(l);<br />
				l = null;<br />
			}</p>
<p>			_loader = null;<br />
			_loader = new Array();<br />
		}<br />
	}<br />
}</p>
<p>to compile it create a fla file with this class as documentClass and to simpleButtons called btn1 and btn2 ,  and change the file name.</p>
<p>i load the same image  100 times and try the method i found here,  i&#8217;m working on a macbook pro and in the  activity monitor i checked that the memory for the firefox goes up  in about 130 Mb, and when the clean method is executed the memory goes down about 50 MB, and it stays there.  the whole memory is not cleaned.</p>
<p>if someone finds code errors please let me know .   this issue is affecting my projects.</p>
<p>bye </p>
<p>LM <img src='http://www.dreaminginflash.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shadow_SB</title>
		<link>http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/comment-page-1/#comment-444</link>
		<dc:creator>Shadow_SB</dc:creator>
		<pubDate>Thu, 14 Aug 2008 07:57:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/#comment-444</guid>
		<description>@Smith

Did you invoke dispose after Event.COMPLETE or unload() ?</description>
		<content:encoded><![CDATA[<p>@Smith</p>
<p>Did you invoke dispose after Event.COMPLETE or unload() ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christopher&#8217;s Blog&#187; Blog Archive &#187; ä¸¤ç¯‡å…³äºŽAS3å†…å­˜æ³„æ¼çš„æ–‡ç« </title>
		<link>http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/comment-page-1/#comment-437</link>
		<dc:creator>Christopher&#8217;s Blog&#187; Blog Archive &#187; ä¸¤ç¯‡å…³äºŽAS3å†…å­˜æ³„æ¼çš„æ–‡ç« </dc:creator>
		<pubDate>Sat, 02 Aug 2008 08:18:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/#comment-437</guid>
		<description>[...] http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/ [...]</description>
		<content:encoded><![CDATA[<div style="padding: 1em; background: #fbfbfb; border: 1px solid #457AA5;">
<p>[...] <a href="http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/" rel="nofollow">http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/</a> [...]</p>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: smith</title>
		<link>http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/comment-page-1/#comment-436</link>
		<dc:creator>smith</dc:creator>
		<pubDate>Thu, 31 Jul 2008 00:07:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/#comment-436</guid>
		<description>Regarding the code:
var li:LoaderInfo = loader.contentLoaderInfo;
if(li.childAllowsParent &amp;&amp; li.content is Bitmap){
(li.content as Bitmap).bitmapData.dispose(); // remove bitmap from memory
}

when running Simulate Download in Flash IDE, got eeror:
Error: Error #2099: The loading object is not sufficiently loaded to provide this information.
	at flash.display::LoaderInfo/get childAllowsParent()
	at com.cfour.app.afl.mural::PopupWindow/disposeImage()
	at com.cfour.app.afl.mural::PopupWindow/closeHandler()

trace(li) got null.

Why?</description>
		<content:encoded><![CDATA[<p>Regarding the code:<br />
var li:LoaderInfo = loader.contentLoaderInfo;<br />
if(li.childAllowsParent &amp;&amp; li.content is Bitmap){<br />
(li.content as Bitmap).bitmapData.dispose(); // remove bitmap from memory<br />
}</p>
<p>when running Simulate Download in Flash IDE, got eeror:<br />
Error: Error #2099: The loading object is not sufficiently loaded to provide this information.<br />
	at flash.display::LoaderInfo/get childAllowsParent()<br />
	at com.cfour.app.afl.mural::PopupWindow/disposeImage()<br />
	at com.cfour.app.afl.mural::PopupWindow/closeHandler()</p>
<p>trace(li) got null.</p>
<p>Why?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kglad</title>
		<link>http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/comment-page-1/#comment-393</link>
		<dc:creator>kglad</dc:creator>
		<pubDate>Sat, 21 Jun 2008 16:21:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.dreaminginflash.com/2007/10/22/memory-leak-in-as3-loader-class/#comment-393</guid>
		<description>sam, are you still checking this thread?</description>
		<content:encoded><![CDATA[<p>sam, are you still checking this thread?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

