> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/godotengine/godot/llms.txt
> Use this file to discover all available pages before exploring further.

# RefCounted

# 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

```gdscript theme={null}
int get_reference_count()
```

Returns the current reference count.

### init\_ref

```gdscript theme={null}
bool init_ref()
```

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

### reference

```gdscript theme={null}
bool reference()
```

Increments the internal reference counter. Returns true if successful.

### unreference

```gdscript theme={null}
bool unreference()
```

Decrements the internal reference counter. Returns true if the object should be freed after the decrement.

## Example Usage

<Tabs>
  <Tab title="GDScript">
    ```gdscript theme={null}
    class MyRefCounted extends RefCounted:
        var data = "example"

    var obj = MyRefCounted.new()
    print(obj.get_reference_count())  # Reference is automatically managed
    ```
  </Tab>

  <Tab title="C#">
    ```csharp theme={null}
    public partial class MyRefCounted : RefCounted
    {
        public string Data = "example";
    }

    var obj = new MyRefCounted();
    ```
  </Tab>
</Tabs>
