Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
WeakRef¶
Inherits: RefCounted < Object
存放 Object。如果该对象为 RefCounted,则不会影响其引用计数。
Description¶
弱引用可以存放 RefCounted,但不会影响其引用计数。可以使用 @GlobalScope.weakref 创建 Object 的弱引用。如果该对象不是引用,弱引用仍然有效,只是对这个对象没有任何影响。弱引用在多个类的变量相互引用的情况下很有用。如果没有弱引用,使用这些类可能会导致内存泄漏,因为这两个引用会阻止彼此被释放。将部分变量设置为弱引用可以防止这种循环依赖,让引用能够被释放。
Methods¶
get_ref ( ) const |
Method Descriptions¶
Variant get_ref ( ) const
返回这个弱引用所引用的 Object。如果该对象不复存在,则返回 null
。