Skip to main content

RefCounted

Inherits: Object

Description

Base class for reference-counted objects. RefCounted instances keep an internal reference counter so that they are automatically released when no longer in use.

Inheritance

RefCounted < Object

Methods

get_reference_count

int get_reference_count()
Returns the current reference count.

init_ref

bool init_ref()
Initializes the internal reference counter. Use this only if you really know what you are doing.

reference

bool reference()
Increments the internal reference counter. Returns true if successful.

unreference

bool unreference()
Decrements the internal reference counter. Returns true if the object should be freed after the decrement.

Example Usage

class MyRefCounted extends RefCounted:
    var data = "example"

var obj = MyRefCounted.new()
print(obj.get_reference_count())  # Reference is automatically managed

Build docs developers (and LLMs) love