Why value-types are stored onto Stacks?

Eric Lippert discusses this here; firstly, it is incorrect that “value types are stored on the stack”. They sometimes are, but not as:

  • fields on a class
  • captured variables
  • variables in an iterator block

When they can be stored on the stack it is a convenient way of modelling their lifetime, but it isn’t required to store them on the stack. You could write a compiler+CLI that doesn’t have a stack, for example.

Leave a Comment