<?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: DisplayObjectContainer.removeAllChildren()</title>
	<atom:link href="http://blog.pirrest.com/2008/03/19/71/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pirrest.com/ru/2008/03/19/71/</link>
	<description>Чому блохи? Тому що чухаються :) Інколи флеш видає щось нове і подекуди не логічне. І це чухається, доки не зрозумієш чому так, а не інакше. А розчухати самотужки не завжди виходить, тож пропоную ловити бліх разом :)</description>
	<lastBuildDate>Thu, 18 Nov 2010 00:42:19 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
	<item>
		<title>By: pirrest</title>
		<link>http://blog.pirrest.com/ru/2008/03/19/71/#comment-54</link>
		<dc:creator>pirrest</dc:creator>
		<pubDate>Thu, 22 May 2008 09:50:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.pirrest.com/2008/03/19/71/#comment-54</guid>
		<description>Чудово :)
Дякую, друже! :)
Іще одне на вуса намотнув, що це не тільки рішення з меншою кількістю програмних символів, а ще й швидкісніше :)</description>
		<content:encoded><![CDATA[<p>Чудово :)<br />
Дякую, друже! :)<br />
Іще одне на вуса намотнув, що це не тільки рішення з меншою кількістю програмних символів, а ще й швидкісніше :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chudesno</title>
		<link>http://blog.pirrest.com/ru/2008/03/19/71/#comment-53</link>
		<dc:creator>chudesno</dc:creator>
		<pubDate>Thu, 22 May 2008 09:36:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.pirrest.com/2008/03/19/71/#comment-53</guid>
		<description>&quot;Essential ActionScript 3.0&quot; (Chapter 20, section Removing All Children):
&quot;It [the top-to-bottom approach] should be avoided because it is slower than the preceding approach of removing children from the bottom up&quot;

The top-to-bottom approach:
while(theParent.numChildren &gt;0){
theParent.removeChildAt(theParent.numChildren-1);
}

The bottom-to-top approach:
while(theParent.numChildren &gt;0){
theParent.removeChildAt(0);
}</description>
		<content:encoded><![CDATA[<p>&#8220;Essential ActionScript 3.0&#8243; (Chapter 20, section Removing All Children):<br />
&#8220;It [the top-to-bottom approach] should be avoided because it is slower than the preceding approach of removing children from the bottom up&#8221;</p>
<p>The top-to-bottom approach:<br />
while(theParent.numChildren &gt;0){<br />
theParent.removeChildAt(theParent.numChildren-1);<br />
}</p>
<p>The bottom-to-top approach:<br />
while(theParent.numChildren &gt;0){<br />
theParent.removeChildAt(0);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chudesno</title>
		<link>http://blog.pirrest.com/ru/2008/03/19/71/#comment-52</link>
		<dc:creator>chudesno</dc:creator>
		<pubDate>Wed, 14 May 2008 20:46:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.pirrest.com/2008/03/19/71/#comment-52</guid>
		<description>Для того чтобы удалить из массива не последний элемент - прийдется сдвинуть все стоящие за ним. shift() работает медленней чем pop(), видимо по этой причине.

var a : Array = new Array();
for (var i : int = 0; i &lt; 40000; i++) {
	a.push(&quot;node&quot; + i);
}

function estimateRemoveAll1() : int {
	var t : uint = flash.utils.getTimer();
	while (a.length) a.shift();
	return flash.utils.getTimer() - t;
}

function estimateRemoveAll2() : int {
	var t : uint = flash.utils.getTimer();
	while (a.length) a.pop();
	return flash.utils.getTimer() - t;
}

trace (estimateRemoveAll1());

for (i = 0; i &lt; 40000; i++) {
	a.push(&quot;node&quot; + i);
}

trace (estimateRemoveAll2());


Но вот для чайлдов получается все с точностью наоборот :).. Видимо там все же не массив. У меня получилось, что удалять с конца примерно в 2 раза дороже чем выкидывать нулевой элемент. Возможно чайлды содержатся в памяти как односвязный список и для того чтобы найти последний, приходится пробежаться по всей очереди...

for (var j : int = 0; j &lt; 1000; j++) {
	addChild(new Sprite());
}

function estimateRemoveAll3() : int {
	var t : uint = flash.utils.getTimer();
	for (var k:int = 0; k &lt; 100000; k++) {
		getChildAt(0);
	}
	return flash.utils.getTimer() - t;
}

function estimateRemoveAll4() : int {
	var tt : uint = flash.utils.getTimer();
	for (var k:int = 0; k &lt; 100000; k++) {
		getChildAt(numChildren - 1);
	}
	return flash.utils.getTimer() - tt;
}

trace (estimateRemoveAll3());


trace (estimateRemoveAll4());</description>
		<content:encoded><![CDATA[<p>Для того чтобы удалить из массива не последний элемент &#8211; прийдется сдвинуть все стоящие за ним. shift() работает медленней чем pop(), видимо по этой причине.</p>
<p>var a : Array = new Array();<br />
for (var i : int = 0; i &lt; 40000; i++) {<br />
	a.push(&#8220;node&#8221; + i);<br />
}</p>
<p>function estimateRemoveAll1() : int {<br />
	var t : uint = flash.utils.getTimer();<br />
	while (a.length) a.shift();<br />
	return flash.utils.getTimer() &#8211; t;<br />
}</p>
<p>function estimateRemoveAll2() : int {<br />
	var t : uint = flash.utils.getTimer();<br />
	while (a.length) a.pop();<br />
	return flash.utils.getTimer() &#8211; t;<br />
}</p>
<p>trace (estimateRemoveAll1());</p>
<p>for (i = 0; i &lt; 40000; i++) {<br />
	a.push(&#8220;node&#8221; + i);<br />
}</p>
<p>trace (estimateRemoveAll2());</p>
<p>Но вот для чайлдов получается все с точностью наоборот :).. Видимо там все же не массив. У меня получилось, что удалять с конца примерно в 2 раза дороже чем выкидывать нулевой элемент. Возможно чайлды содержатся в памяти как односвязный список и для того чтобы найти последний, приходится пробежаться по всей очереди&#8230;</p>
<p>for (var j : int = 0; j &lt; 1000; j++) {<br />
	addChild(new Sprite());<br />
}</p>
<p>function estimateRemoveAll3() : int {<br />
	var t : uint = flash.utils.getTimer();<br />
	for (var k:int = 0; k &lt; 100000; k++) {<br />
		getChildAt(0);<br />
	}<br />
	return flash.utils.getTimer() &#8211; t;<br />
}</p>
<p>function estimateRemoveAll4() : int {<br />
	var tt : uint = flash.utils.getTimer();<br />
	for (var k:int = 0; k &lt; 100000; k++) {<br />
		getChildAt(numChildren &#8211; 1);<br />
	}<br />
	return flash.utils.getTimer() &#8211; tt;<br />
}</p>
<p>trace (estimateRemoveAll3());</p>
<p>trace (estimateRemoveAll4());</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pirrest</title>
		<link>http://blog.pirrest.com/ru/2008/03/19/71/#comment-50</link>
		<dc:creator>Pirrest</dc:creator>
		<pubDate>Wed, 07 May 2008 12:17:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.pirrest.com/2008/03/19/71/#comment-50</guid>
		<description>Пробачте, але я не бачу проблеми у видаленні с початку а не з кінця. Можете пояснити?</description>
		<content:encoded><![CDATA[<p>Пробачте, але я не бачу проблеми у видаленні с початку а не з кінця. Можете пояснити?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chudesno</title>
		<link>http://blog.pirrest.com/ru/2008/03/19/71/#comment-49</link>
		<dc:creator>chudesno</dc:creator>
		<pubDate>Wed, 07 May 2008 10:35:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.pirrest.com/2008/03/19/71/#comment-49</guid>
		<description>Я не уверен насчет реализации чайлдов, но ИМХО может удалять лучше с конца? Если это массив, то выкидывать каждый раз первый элемент не слишком оптимальное решение...</description>
		<content:encoded><![CDATA[<p>Я не уверен насчет реализации чайлдов, но ИМХО может удалять лучше с конца? Если это массив, то выкидывать каждый раз первый элемент не слишком оптимальное решение&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dimpiax</title>
		<link>http://blog.pirrest.com/ru/2008/03/19/71/#comment-48</link>
		<dc:creator>dimpiax</dc:creator>
		<pubDate>Wed, 16 Apr 2008 16:55:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.pirrest.com/2008/03/19/71/#comment-48</guid>
		<description>ну да, это мой первый способ вычищения всех чайлдов из опредеоенной области ))
кстати такой тоже неплох))

public function removeAllChildren() : void { 
    while (this.numChildren) this.removeChildAt(0);
}</description>
		<content:encoded><![CDATA[<p>ну да, это мой первый способ вычищения всех чайлдов из опредеоенной области ))<br />
кстати такой тоже неплох))</p>
<p>public function removeAllChildren() : void {<br />
    while (this.numChildren) this.removeChildAt(0);<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>

