

In other words, all variables which are related to int data type are de-allocated in ‘LIFO’ fashion from the stack. When it passes the end control, it clears all the memory variables which are assigned on stack. The time it hits the new keyword, it allocates on "heap".Įxiting the method (the fun): Now finally the execution control starts exiting the method. The statement, Class1 cls1 does not allocate memory for an instance of Class1, it only allocates a stack variable cls1 (and sets it to null). One more important point to note here is reference pointers are allocated on stack. Heap is used for dynamic memory allocation. ‘Heap’ does not track running memory, it’s just a pile of objects which can be reached at any moment of time. When this line is executed, it creates a pointer on the stack and the actual object is stored in a different type of memory location called ‘Heap’.
#Queue vs stack vs heap series#
You can think about stack as a series of compartments or boxes put on top of each other. As the name says stack, it stacks this memory allocation on top of the first memory allocation.

Angular Interview Questions with Answers.ASP.NET MVC Interview Questions & Answers.

įor further reading, do watch the below interview preparation videos and step by step video series. In case you do not want to read my complete article, you can watch the below video on Stack vs Heap | Boxing vs Unboxing | Value Type vs Reference Type. Performance implication of boxing and unboxing.So which data types are ref types and which are value types?.What goes inside when you declare a variable?.
