title: stsfld vs stfld
body: <p>Looking at the difference between the stfld and stsfld il op codes, the stfld has a null reference check while stsfld does not. Why is this? Is it because static fields are on the high-frequency heap and so they are not garbage collected? </p>
  
  <p><a href="http://msdn.microsoft.com/library/system.reflection.emit.opcodes.stfld.aspx" rel="nofollow">http://msdn.microsoft.com/library/system.reflection.emit.opcodes.stfld.aspx</a></p>
  
  <blockquote>
    <p>The stack transitional behavior, in sequential order, is:</p>
    
    <ol>
    <li>An object reference or pointer is pushed onto the stack.</li>
    <li>A value is pushed onto the stack.</li>
    <li>The value and the object reference/pointer are popped from the
    stack; the value of field in the object is replaced with the supplied
    value.</li>
    </ol>
    
    <p>The stfld instruction replaces the value of a field of an object (type
    O) or via a pointer (type native int, &amp;, or *) with a given value.
    Field is a metadata token that refers to a field member reference. The
    stfld instruction can have a prefix of either or both of Unaligned and
    Volatile.</p>
    
    <p>NullReferenceException is thrown if the object reference or pointer is
    a null reference and the field isn't static.</p>
    
    <p>MissingFieldException is thrown if field is not found in the metadata.
    This is typically checked when the Microsoft Intermediate Language
    (MSIL) instruction is converted to native code, not at runtime.</p>
  </blockquote>