Flash 应用程序速度变慢 [removeChild]

发布于 2024-09-12 06:17:44 字数 174 浏览 2 评论 0原文

我的 Flash 应用程序出现问题,因为它运行一段时间后,最终开始变慢。我的应用程序涉及需要使用 addChild() 方法复制的内容。我在互联网上阅读了一些信息,其中指出应用程序速度减慢或滞后的原因是removeChild() 没有从内存中删除子项。

有什么办法可以把孩子从记忆中删除吗?任何意见都将受到赞赏。谢谢。

I have a problem with my flash application because after a while that it is running, it eventually starts to slow down. My application involves something that needs to be replicated with the addChild() method. I've read some info on the internet which states that the cause of the slowing down or the lag in the application is that the removeChild() does not remove the child from the memory.

Are there any ways on how I can remove the child from the memory too? Any inputs are appreciated. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神经大条 2024-09-19 06:17:44

查看这篇关于 AS3 资源管理的三部分文章作者:格兰特·斯金纳。

Check out this 3-part article on resource management in AS3 by Grant Skinner.

筑梦 2024-09-19 06:17:44

看起来您正在创建新对象,将其添加到舞台中并从舞台中删除不需要的对象,这可能会导致速度变慢,因为内存中会有很多不需要的对象。在Flash AS3中,不能完全依赖GC进行垃圾清理。因此,最好的方法是生成尽可能少的垃圾,并在需要新对象时回收未使用的对象。
例如,一个应用程序不断地在舞台上放置一些圆圈,并以固定的时间间隔删除其中一些圆圈。因此对于这种资源实现一个资源池。

 public class ResourcePool {
  static function getCircle(prop:Object):Circle {
    //check if you already have some circle objects
    //if yes pick one apply the prop and return
    // else create a new circle with specified prop and return
  }
  static function recycle(circle:Circle):void {
    //add it to available resource array
  }
}

Now when you need a circle object then ask the ResourcePool for that:

 var c:Circle = ResourcePool.getCircle(someProperty);

And whenever you are removing a circle then recycle it properly so that it can be used later.

//remove circle1 object
ResourcePool.recycle(circle1);

It looks like you are creating new Objects adding it to your stage and removing unwanted objects from the stage, which might lead to slow speed as there will be lots of unwanted object in the memory. In flash AS3, you can not totally rely on GC for garbage cleanup. So the best approach is to generate least possible amount of garbage and recycle unused objects whenever you need a new object.
For example, an application keeps putting some circle to the the stage and removing some of them at fixed time interval. So for this kind of resource implement a resource pool.

 public class ResourcePool {
  static function getCircle(prop:Object):Circle {
    //check if you already have some circle objects
    //if yes pick one apply the prop and return
    // else create a new circle with specified prop and return
  }
  static function recycle(circle:Circle):void {
    //add it to available resource array
  }
}

Now when you need a circle object then ask the ResourcePool for that:

 var c:Circle = ResourcePool.getCircle(someProperty);

And whenever you are removing a circle then recycle it properly so that it can be used later.

//remove circle1 object
ResourcePool.recycle(circle1);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文