Wednesday, August 10, 2011

Reference types stored on Head and value types on Stack

We usually think that reference types are stored on the Head, right. Yes we are right.

But we do think that value types are stored on Stack and here we are always not right.

Only local variables are stored in the stack, so what's this local variables? Local variables declared within methods and method parameters live on stack. So when on heap? If they are declared within the class. Value types lives on wherever they are declared. So if they are created in reference type ex, class they would be stored on heap, and if declared locally ex. within method then stack.

No comments: