删除父在AS3:这是否释放所使用的所有孩子们的记忆? [英] Removing Parent in AS3: Does this free the memory used by all the children?

查看:162
本文介绍了删除父在AS3:这是否释放所使用的所有孩子们的记忆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个相当大的闪存项目,所以我很担心内存使用情况。在应用程序的每个部分结束时,我删除了包含内容的总体父元素。虽然这个删除父,这是否也是免费为每个包含在这个孩子们的记忆,或者我应该跑一个迭代消除这些之前,移除父?

I'm making a rather large flash project and so I'm concerned about memory usage. At the end of each section of the application I remove the overarching parent element that holds the content. Although this remove the parent, does this also free up the memory for each of the children contained within this, or should I run an iteration to remove those prior to removing the parent?

我给多一点的解释在情况下,我不是我想要的EX pressing:

I'll give a little more explanation in-case I'm not expressing what I want:

addChild(movie1);
movie1.addChild(movie2);
movie1.addChild(movie3);

通过使用这种code:

By using this code:

removeChild(movie1);

是否从内存中删除MOVIE2和MOVIE3或者他们仍然保存,只是未链接?

Does it remove movie2 and movie3 from memory or are they still stored, just unlinked?

推荐答案

好了,没有什么是从内存中删除,到目前为止,这真的取决于MOVIE1参考。比方说,在申请后要添加MOVIE1一遍,你会发现,MOVIE1不仅还在这里,但它也包含MOVIE2和放大器; MOVIE3。

Well, nothing is removed from memory so far , it really depends on how movie1 is referenced. Let's say that later in the application you want to add movie1 again, you should find that movie1 is not only still here but it also contains 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
}

这篇关于删除父在AS3:这是否释放所使用的所有孩子们的记忆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆