我正在制作一个相当大的闪存项目,因此我担心内存使用情况。在应用程序的每个部分的末尾,我删除了保存内容的总体父元素。虽然这会删除父级,但这是否也会释放其中包含的每个子级的内存,或者我应该在删除父级之前运行迭代来删除这些子级?
如果我没有表达我想要的内容,我会给出更多解释:
addChild(movie1);
movie1.addChild(movie2);
movie1.addChild(movie3);
通过使用此代码:
removeChild(movie1);
它是否从内存中删除 movie2 和 movie3 或者它们仍然存储,只是取消链接?
最佳答案
如果 movie2
和 movie3
不再被另一个对象引用,则应该对它们进行垃圾回收。这同样适用于movie1
。
来自Creating visual Flex components in ActionScript :
To programmatically remove a control, you can use the removeChild() or removeChildAt() methods. You can also use the removeAllChildren() method to remove all child controls from a container. Calling these methods does not actually delete the objects. If you do not have any other references to the child, Flash Player includes it in garbage collection at some future point. But if you stored a reference to that child on some object, the child is not removed from memory.
关于actionscript-3 - 删除 AS3 中的父级 : Does this free the memory used by all the children?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3734228/