class_weakref.rst 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the WeakRef.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_WeakRef:
  5. WeakRef
  6. =======
  7. **Inherits:** :ref:`Reference<class_reference>` **<** :ref:`Object<class_object>`
  8. **Category:** Core
  9. Brief Description
  10. -----------------
  11. Holds an :ref:`Object<class_object>`, but does not contribute to the reference count if the object is a reference.
  12. Member Functions
  13. ----------------
  14. +--------------------------------+---------------------------------------------------------+
  15. | :ref:`Variant<class_variant>` | :ref:`get_ref<class_WeakRef_get_ref>` **(** **)** const |
  16. +--------------------------------+---------------------------------------------------------+
  17. Description
  18. -----------
  19. A weakref can hold a :ref:`Reference<class_reference>`, without contributing to the reference counter. A weakref can be created from an :ref:`Object<class_object>` using :ref:`@GDScript.weakref<class_@GDScript_weakref>`. If this object is not a reference, weakref still works, however, it does not have any effect on the object. Weakrefs are useful in cases where multiple classes have variables that refer to each other. Without weakrefs, using these classes could lead to memory leaks, since both references keep each other from being released. Making part of the variables a weakref can prevent this cyclic dependency, and allows the references to be released.
  20. Member Function Description
  21. ---------------------------
  22. .. _class_WeakRef_get_ref:
  23. - :ref:`Variant<class_variant>` **get_ref** **(** **)** const
  24. Returns the :ref:`Object<class_object>` this weakref is referring to.