ActionScript 和弱引用行为
我读过一些关于 ActionScript 弱引用的文章。有两种类型。
- 使用
Dictionary
类的技巧。 EventDispatcher
类。
我预计当最后一个强引用被删除时,弱引用对象会立即消失。 (无论 GC 行为如何)但是这些技巧并没有那么有效。仅弱引用的对象还存活一段时间,并且在下一次 GC 时看起来消失。删除所有强引用并不会使弱引用对象从对象图中消失。 (我知道它不会立即被删除)
我错了还是只是 ActionScript 使用了不同的行为?
I read some articles about ActionScript's weak references. There are two types.
- Trick with
Dictionary
class. EventDispatcher
class.
I expected weakly referenced object to be disappeared immediately when last strong reference removed. (regardless of GC behavior) But those tricks didn't work like that. The object referenced only weakly still live a while, and looks disappear when next GC time. Removing all of strong references didn't make weakly referenced object to be disappeared from object graph. (I know it'll not be deleted immediately)
Am I wrong or just ActionScript is using different behavior?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,所有弱引用意味着 GC 不会将其计为对对象的引用 - 引用计数是 GC 知道对象仍在使用中的方法之一。在回收内存之前,您仍然需要运行垃圾收集。
如果您想了解垃圾收集的工作原理,请查看:http://divillysausages.com/blog/tracking_memory_leaks_in_as3< /a> (我自己的网站)或:http://jpauclair。 net/2009/12/23/tamarin-part-iii-current-garbage-collector-in-flash-10-0/ (非常深入)
Yes, all weak references mean is that the GC doesn't count it as a reference to an object - reference counting is one of the ways that the GC knows an object is still in use. You still need the garbage collection to run before the memory is reclaimed.
If you want an overview of how Garbage collection works, check out that: http://divillysausages.com/blog/tracking_memory_leaks_in_as3 (my own site) or that: http://jpauclair.net/2009/12/23/tamarin-part-iii-current-garbage-collector-in-flash-10-0/ (goes really in depth)