Quick answer: Godot 4 C# Godot.Collections.Array.Add allocating GC garbage each call? Each Add boxes the value for Variant - use typed List and convert once at the boundary.

Per-frame inventory rebuild allocates 200KB. Profiler shows Variant boxing as the cause.

Use List<T> internally

List<Item> tmp = new();
tmp.Add(item);
// at end:
result = new Godot.Collections.Array(tmp);

One conversion at the boundary. Hot loop allocates nothing.

Pre-size Godot Arrays

If you must use Godot.Collections.Array, set its capacity up front. Avoids per-Add reallocation.

Profile with the .NET allocator

Standalone .NET profiler shows the boxing site precisely. Internal Godot profiler is less specific.

“Godot.Collections is interop. Interop costs.”

For new code, default to C# native collections. Convert to Godot.Collections only when crossing the engine boundary.

Related reading