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
繼承: RefCounted < Object
存放 Object。如果該物件為 RefCounted,則不會影響其引用計數。
說明
弱引用可以存放 RefCounted,但不會影響其引用計數。可以使用 @GlobalScope.weakref() 建立 Object 的弱引用。如果該對象不是引用,弱引用仍然有效,只是對這個物件沒有任何影響。弱引用在多個類的變數相互引用的情況下很有用。如果沒有弱引用,使用這些類可能會導致記憶體洩漏,因為這兩個引用會阻止彼此被釋放。將部分變數設定為弱引用可以防止這種迴圈依賴,讓引用能夠被釋放。
方法
get_ref() const |
方法說明
返回這個弱引用所引用的 Object。如果該物件不復存在,則返回 null。