godotengine / godotengine/godot

Editor leaks CanvasItem RIDs, TextLine/ShapedText objects, and ObjectDB instances after inspecting a node with deeply nested `Array[Resource]` properties

Open
#121,663 2 comments 0 reactions 0 assignees View on GitHub
bug needs testing topic:editor
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

4.7.1

### System information

Windows 10, Godot Engine v4.7.1.stable.mono.official.a13da4feb ,D3D12 renderer, Jolt Physics 3D,VIDIA GeForce RTX 5070 Laptop GPU

### Issue description

When you select a node in the editor whose `@export` properties include deeply nested `Array[Resource]` (e.g. `Array[CustomResource]` where each element itself contains `Array[AudioStream]` or `Array[Resource]`), the editor inspector displays the nested contents, creating CanvasItem RIDs, shaped-text objects (TextLine/ShapedTextDataAdvanced), texture RIDs, style boxes, and other inspector UI resources. Closing the editor **after** having selected such a node leaks these resources.

If the node is **not** selected, or if a different node without deeply nested resource arrays is selected instead, these resources are cleaned up normally and no leak occurs.

Concretely, after selecting a `SoundBank` node (Godot-addon `resonate` — but the bug is reproducible purely via the engine[^1]) whose properties look like:

```
@export var events: Array[SoundEventResource] # 4 elements
# each SoundEventResource has:
# @export var streams: Array[AudioStream] # 3–7 elements
```

closing the editor prints:

```
WARNING: 32 RIDs of type "CanvasItem" were leaked.
ERROR: 8 RID allocations of type 'N10RendererRD14TextureStorage7TextureE' were leaked.
WARNING: 16 RIDs of type "Texture" were leaked.
ERROR: 128 RID allocations of type 'PN18TextServerAdvanced22ShapedTextDataAdvancedE' were leaked.
WARNING: 174 ObjectDB instances were leaked.
ERROR: 16 resources still in use at exit.
```

[^1]: The same leak pattern can be reproduced with any `@export var list: Array[Resource]` where each element is a custom `Resource` subclass that itself holds an `Array[Resource]`. No addon code is required beyond plain GDScript.

### Impact

- Pollutes the editor console with scary-looking leak warnings every time the user inspects a node that uses nested resource arrays — a very common pattern in Godot projects.
- The leaked CanvasItem RIDs and ObjectDB instances indicate the editor’s inspector does not fully tear down the UI elements it creates when displaying nested resources, which could mask real resource leaks in user code.

### Steps to reproduce

1. Create a new Godot 4.7.1 project.
2. Create two GDScript files:

```gdscript
# item.gd
extends Resource
class_name MyItem
@export var sub_items: Array[Resource] # nest deeper
@export var name: String
```

```gdscript
# holder.gd
extends Node
class_name MyHolder
@export var items: Array[MyItem]
```

3. Create a scene with a single `MyHolder` node, populate `items` with 3–4 `MyItem` resources, and give each `MyItem` 4–5 `sub_items` (just fill with empty `Resource` references or small resources).
4. Open the scene in the editor.
5. **Select** the `MyHolder` node so the inspector shows the nested arrays.
6. Close the editor.
7. Observe the leak messages in the console output.

If you repeat steps 2–6 but **skip step 5** (do not select the holder node before closing), no leaks appear.

### Minimal reproduction project (MRP)

[mrp.zip](https://github.com/user-attachments/files/30292699/mrp.zip)

Image

Contributor guide

Open the contributing guide

Research direction

Run the linked minimal reproduction project, select the holder node, and confirm the leak warnings when closing the editor; compare this with closing without selecting it. Trace the editor inspector path that displays nested Array[Resource] properties, and consider the work complete when the reproduction no longer reports the listed leaked RIDs, objects, or resources.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.