![]() |
1
1
好吧,到目前为止,记忆中没有任何东西被移除,这真的取决于电影1是如何被引用的。让我们假设在稍后要再次添加movie1的应用程序中,您应该发现movie1不仅仍在这里,而且还包含movie2&movie3。 var movie1:MovieClip; whatever(); anotherMethod(); function whatever():void { movie1 = new MovieClip(); var movie2:MovieClip = new MovieClip(); var movie3:MovieClip = new MovieClip(); movie1.addChild(movie2); movie1.addChild(movie3); addChild(movie1); whateverElse(); } function whateverElse():void { //here, nothing is garbage collected, movie1 exists outside //the scope of this function removeChild(movie1); //now you can tryThis(); //but if you do this you're effectively killing movie2 & movie3 , since //they're not referenced anywhere else. removeChild(movie1); movie1 = null; //this is going to throw an error , movie1's gone! tryThis(); } function tryThis():void { //yes ,it's still here with all its content addChild(movie1); } function anotherMethod():void { var movieN:MovieClip = new MovieClip(); var movie2:MovieClip = new MovieClip(); var movie3:MovieClip = new MovieClip(); movieN.addChild(movie2); movieN.addChild(movie3); // do all you need to do... // then removeChild( movieN); getOut(); } function getOut():void { //life goes on without movieN, movie2 & movie3 //waiting to be garbage collected } |
![]() |
2
3
如果
从 Creating visual Flex components in ActionScript :
|
![]() |
3
0
当然,它删除了所有3个。 儿童电影1有两个孩子,电影2+3。 如果他因故死亡,孩子们也可能会死去。 也许我错了,但你也可以尝试:
|