weak_ref_alive

With this function you can check the weak reference to a struct to see if it is still "alive" or not. You supply the weak reference to check (as returned by the function weak_ref_create()), and the function will return true if the struct is still being referenced somewhere or false if it's not and has been garbage collected. Note that if you supply a value that is not a weak reference, the function will return undefined.

 

Syntax:

weak_ref_alive(weak_ref);

ArgumentTypeDescription
weak_refStruct Weak ReferenceThe weak reference to the struct you want to check.

 

Returns:

Boolean (or undefined)

 

Example:

if (weak_ref_alive(inventory_ref))
{
    inventory = -1;
}

The above code checks a weak reference to a struct and if it is still alive the variable referencing it is set to -1, de-referencing the struct and enabling it to be garbage collected.