CA2014: Do not use stackalloc in loops
| Value | |
|---|---|
| Rule ID | CA2014 |
| Category | Reliability |
| Fix is breaking or non-breaking | Non-breaking |
Cause
Using the C# stackalloc expression inside of a loop.
Rule description
The C# stackalloc expression allocates memory from the current stack frame, and that memory may not be released until the current method call returns. If stackalloc is used in a loop, it can lead to stack overflows due to exhausting the stack memory.
How to fix violations
Move the stackalloc expression outside of all loops in the method.
When to suppress warnings
It may be safe to suppress the warning when the containing loop or loops are invoked only a finite number of times, such that the overall amount of memory allocated across all stackalloc operations is known to be relatively small.
See also
Povratne informacije
Pošalјite i prikažite povratne informacije za