ReSharper 2026.1 Help

Code inspection: Using stackalloc inside loop

This inspection reports stackalloc expressions inside loops. Memory allocated with stackalloc is released only when the current method returns, not at the end of each loop iteration. Repeating it inside a loop can therefore cause temporary stack growth that looks like a leak.

Example

for (int i = 0; i < 10; i++) { Span<int> buffer = stackalloc int[128]; Use(buffer); }
Span<int> buffer = stackalloc int[128]; for (int i = 0; i < 10; i++) { Use(buffer); }
01 April 2026