In your example anotherInt
would be allocated to the Heap. This is because anotherInt
is a field of Form1
, which is a Heap allocated object. The Stack is associated with a thread & contains only the references/objects necessary for the currently executing code. So to answer your question about methods coming under a class, you're not entierly correct there.
While methods belong to a class, they are executable blocks of code rather than memory blocks associated directly with a class(which is what anotherInt
is). One of the best ways to examine this type of allocation is to use a memory debugger like WinDbg & actually examine your thread stacks vs. the Heap. This will give you the clearest picture of where a particular struct is actually allocated.
In an extremely simplified sense: Stack = addresses necessary for currently executing code stack, Heap = everything else. But ultimatley Jon B is spot on w/ his link to Eric's blog. You really don't need to know where your objects are allocated.
EDIT: Including the blog link.