Using the C# stackalloc expression inside of a loop.
Rule descriptionThe 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.
Move the stackalloc
expression outside of all loops in the method.
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.
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
#pragma warning disable CA2014
// The code that's violating the rule is on this line.
#pragma warning restore CA2014
To disable the rule for a file, folder, or project, set its severity to none
in the configuration file.
[*.{cs,vb}]
dotnet_diagnostic.CA2014.severity = none
To disable this entire category of rules, set the severity for the category to none
in the configuration file.
[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-Reliability.severity = none
For more information, see How to suppress code analysis warnings.
See alsoRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4