Skip to content
Discussion options

You must be logged in to vote

As you've read, the only guarantee you get is that there is no guarantee. You don't necessarily need to use Span.Clear, but you need to ensure you don't read data which wasn't previously written.


In practice though, locals (including stack allocations) will always be initialized to zero unless you use SkipLocalsInit, which is why you aren't ever seeing it as non-zero. (I don't think it has ever actually differed between debug and release builds.)

However if you're relying on this, you're still relying on unspecified behavior. You're also creating a ticking time bomb if anyone were to apply SkipLocalsInit project-wide. (Which is not uncommon in performance-minded code bases.)

If you do wa…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by samuel-lucas6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants