Skip to main content

weakref

Function weakref 

pub fn weakref(obj: &Variant) -> Variant
Expand description

§Specific notes for this function

Use of weakref() is discouraged. See WeakRef for a detailed explanation and better alternatives.

§Godot docs

Returns a WeakRef instance holding a weak reference to obj. Returns an empty WeakRef instance if obj is null. Prints an error and returns null if obj is neither Object-derived nor null.

A weak reference to an object is not enough to keep the object alive: when the only remaining references to a referent are weak references, garbage collection is free to destroy the referent and reuse its memory for something else. However, until the object is actually destroyed the weak reference may return the object even if there are no strong references to it.