PDA

View Full Version : delete vs removeChild


chartermatrix
09-19-2008, 01:31 PM
I have this code:

if (sName && aMap[sLayer].getChildByName(sName))
{
delete aMap[sLayer].getChildByName(sName);
aMap[sLayer].removeChild( aMap[sLayer].getChildByName(sName));
}

If a name is passed and a movieclip with that name exists in aMap[sLayer]
delete it.
remove it.

When I comment out the removeChild line the delete function doesn't seem to do anything. I want to permanently delete the clip from the display list (i think.., display list is still kind of foreign to me)

xxneon
09-19-2008, 02:10 PM
to remove items from the display list you want to use removeChild().. delete is really only to destroy dynamically created variables .. it doesn't destroy the variables value .. thats when you get into garbage collection and if the object that is in memory is marked for removal.

Bombdogs
09-19-2008, 02:10 PM
I believe delete removes the reference & allows it to be garbage collected sometime in the future to free up the memory it uses. But as you have it on a display list still it can't be garbage collected. You need to do both to get rid of it completely or just remove it from the display list if you intend to use it again sometime in the future.

PMF

chartermatrix
09-19-2008, 03:59 PM
to remove items from the display list you want to use removeChild().. delete is really only to destroy dynamically created variables .. it doesn't destroy the variables value .. thats when you get into garbage collection and if the object that is in memory is marked for removal.

Is Garbage Collection something I need to know or does flash take care of it?
Can you give me a link to Garbage Collection and good practice ?

Thanks both of you

xxneon
09-19-2008, 04:33 PM
Garbage Collection is something that flash does in the background.. Its just what Adobe calls how flash handles removing things from memory that are no longer used by anything in the flash app.. if you google it you'll find tons of articles about it..

chartermatrix
09-19-2008, 04:55 PM
thanks!