# Managed

This type represents a managed object. You cannot create an instance of this type directly.

Every object, that inherits from this type, must be `Create`d before use. The rendering system will only create them automatically, if you happen to lose a device object (e.g. minimize the game window, and then restore it) and only if you add your objects to manage table in [`draw`](https://lua.fatality.win/draw.html).

### obj﻿ <a href="#obj" id="obj"></a>

[<kbd><mark style="background-color:purple;">**Field**<mark style="background-color:purple;"></kbd>](#user-content-fn-1)[^1][<kbd><mark style="background-color:orange;">**Read only**<mark style="background-color:orange;"></kbd>](#user-content-fn-2)[^2]

Type: [`Ptr`](https://lua2.fatality.win/api/types/ptr)

Pointer to a GPU object. If this object is not created, this field will be `nil`. You can use the value of this field to pass it to [`Command`](https://lua2.fatality.win/api/instances/draw/layer/command) directly for example, or if you (for whatever reason we don't recommend you doing) want to have a direct control over the pointer - cast it to FFI's `cdata`.

***

## Create﻿ <a href="#create" id="create"></a>

[<kbd><mark style="background-color:purple;">**Method**<mark style="background-color:purple;"></kbd>](#user-content-fn-3)[^3]

Creates a managed object in GPU memory.

{% hint style="success" %}
You should `Create()` an object only once. Invoking this method after the object was created will be meaningless.
{% endhint %}

**Arguments**

None.

**Returns**

Nothing.

**Example**

```lua
tex:Create();
```

***

## Destroy﻿ <a href="#destroy" id="destroy"></a>

[<kbd><mark style="background-color:purple;">**Method**<mark style="background-color:purple;"></kbd>](#user-content-fn-3)[^3]

Destroys a managed object in GPU memory.

{% hint style="danger" %}
Never destroy a GPU object if it is being used in rendering (for example, when you have pushed some shape that uses a texture, and then destroyed that texture). This will lead to undefined behavior, and most likely, \*\***crash the game** \*\*.
{% endhint %}

**Arguments**

None.

**Returns**

Nothing.

**Example**

```lua
font:Destroy();
```

[^1]: This field is a regular field that must be accessed using a dot (.)

[^2]: This field is a read only field, and you cannot change its value. This does not apply to child fields, if any.

[^3]: This field is a method and must be invoked using a colon (:)
