AS3 - 内存管理 [英] AS3 - Memory management

查看:229
本文介绍了AS3 - 内存管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题关于AS3内存管理我不知道是否有人可以帮助我。

I have a question regarding AS3 memory management I wonder if anyone could help me with.

假如我创建一个类的实例变量,在这种情况下,或稳健型:

Supposing I created an instance variable for a Class, in this case or type Sound:

public class SoundStore extends Sprite{

var s:Sound;

然后各种类函数中我引用这个变量多次,我想在一个新的声音加载每个时间:

Then within various class functions I referenced this variable multiple times, each time I wanted to load in a new sound:

s = new Sound();

我是正确的思想,我创建了一个新的声音,每次我将覆盖previous分配的内存?

Am I correct in thinking that each time I created a new Sound I would be overwriting the previous allocated memory?

感谢

推荐答案

没有。 AS3是一个垃圾收集的语言,它使用引用计数来处理未使用的对象。

No. AS3 is a garbage collected language, which uses reference counting to dispose of unused objects.

取值变量是,在内部,指向的内存块,其中包含一个声音对象。每次你做 S =新的声音() AS3会在内存中创建一个新的声音对象,并设置<$ C $ç>取值指针,它指向对象的地址。旧的对象仍然存在于内存中。如果你有旧的对象的引用,垃圾收集器将在某个时候处理的对象,其下通常集合一轮。这意味着,在任何时候,你可以在内存中有多个声音对象没有被引用,但仍在使用的资源。垃圾收集器的目的是通过所有分配对象定期拖网和处置他们,如果有他们的引用。

The s variable is, internally, a pointer to a block of memory that contains a Sound object. Every time you do s = new Sound() AS3 will create a new Sound object in memory and set the s pointer to the address of that object. The old object still exists in memory. If you have no references to the old object, the garbage collector will dispose of the object at some point, usually its next collection round. This means that at any point in time you may have multiple Sound objects in memory that aren't being referenced but that are still using up resources. The garbage collector is designed to periodically trawl through all allocated objects and dispose them if there are no references to them.

下面是关于在Flash / AS3的GC一篇很好的文章:的http:// www.adobe.com/devnet/flashplayer/articles/garbage_collection.html

Here's a nice article on the GC in Flash / AS3: http://www.adobe.com/devnet/flashplayer/articles/garbage_collection.html

这篇关于AS3 - 内存管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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