You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Godot 4, signals connected with `+=` syntax must be manually disconnected with `-=` to prevent memory leaks. Unlike Godot 3, signals in Godot 4 do not automatically disconnect when nodes are freed.
6
+
7
+
**Rule ID**: GD0001
8
+
**Category**: Memory
9
+
**Severity**: Warning
10
+
11
+
## Problem
12
+
13
+
When you connect a signal using `+=` but never disconnect it with `-=`, the connected object will not be garbage collected even after the node is freed, leading to memory leaks.
**Recommendation**: Use named methods instead of lambda expressions for signals that need to be disconnected.
77
+
78
+
### Static Methods
79
+
80
+
Static method connections typically don't cause memory leaks and are ignored by this rule:
81
+
82
+
```csharp
83
+
publicoverridevoid_Ready()
84
+
{
85
+
// No warning - static methods don't typically cause leaks
86
+
HealthChanged+=HealthLogger.LogHealth;
87
+
}
88
+
```
89
+
90
+
### Singleton Classes
91
+
92
+
For singleton classes (classes with a static Instance property or AutoLoad attribute), you can suppress warnings using either `.editorconfig` or MSBuild properties:
0 commit comments