本文介绍了为什么AS3默认情况下不使用弱引用? (事件监听器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在调用addEventListener()来为WeakReference的默认值是假的。许多内存问题可以通过在WeakReferences解决;事实上,一些业内专家强烈建议总是使用与听众弱引用。

The default value for weakReference in the call to addEventListener() is false. Many memory issues can be resolved by using weakReferences; in fact, some industry experts "strongly recommend always using weak references with listeners".

如果是这样的话,能有人为我提供一个很好的理由的WeakReference默认为true? (请注意,我不问为什么会有人曾经想要一个侦听器,不是一个WeakReference的,而是为什么WeakReference的= false是默认值)

If this is the case, can someone provide me with a good reason why weakReference defaults to true? (Note that I'm not asking why someone would ever want a listener that is not a weakReference, but rather why weakReference=false is the default)

谢谢! :)

推荐答案

另外一个原因可能是,听者机制日期的方式,从在没有垃圾收集,因此没有弱引用了。在那些日子里,它是在哪里匿名函数中使用的监听器,所以只能参照这样的功能将成为听众共同的地方。作为放出的语言和弱参考特征的溶液,它被预期的默认行为将是相同迄今所使用的一个,也就是没有弱引用

Another reason may be that the listener mechanism date way back from when there was no garbage collection and thus no weak references. In those days it was common place that the listeners where used with anonymous functions, so the only reference to such function would be in the listener. As the language evolved and the weak reference feature was added, it was expected that the default behavior would be the same as the one used so far, and that is no weak references.

所以,总之,加弱引用时,它仍然预计监听器的默认行为是迄今为止所使用的相同。因此,弱引用是另类,而默认。

So, in short, when the weak reference was added, it was still expected that the default behavior of the listeners was the same used so far. So the weak reference was the alternative, rather that the default.

在今天的弱引用,在监听器使用这些匿名函数最终会与功能被删除几乎只要它被添加,没有目的可言(也可能是打破了很多code,老新,这取决于听众的强引用。

With today’s weak references, using such anonymous functions in a listener would end up with the function being deleted almost as soon as it is added, serving no purpose at all (and probably breaking a lot of code, old and new, which depends on the strong references of the listeners.

这篇关于为什么AS3默认情况下不使用弱引用? (事件监听器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 19:20