0% found this document useful (0 votes)
16 views7 pages

10.1 - Fundamentals Recap

The document discusses key differences between the stack and heap in computing memory. The stack stores method call frames containing parameters and local variables, while the heap stores objects created by the 'new' keyword. When a method returns, its local variables are destroyed but objects on the heap remain until garbage collection reclaims dereferenced memory. It also summarizes value types, reference types, boxing/unboxing, immutable strings, and the intermediate language used in .NET applications.

Uploaded by

Misa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views7 pages

10.1 - Fundamentals Recap

The document discusses key differences between the stack and heap in computing memory. The stack stores method call frames containing parameters and local variables, while the heap stores objects created by the 'new' keyword. When a method returns, its local variables are destroyed but objects on the heap remain until garbage collection reclaims dereferenced memory. It also summarizes value types, reference types, boxing/unboxing, immutable strings, and the intermediate language used in .NET applications.

Uploaded by

Misa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

The stack

- Tracks methods calls


- Contains frames which hold parameters, return address
and local variables for each method call
- A stack frame is removed when returning from a
method. All local variables go out of scope at this
point. 
- If you call too many methods, the stack will fill up
completely and .NET throws a StackOverflow exception.
The heap
- The new keyword creates objects on the heap
- Code that uses objects on the heap is slightly slower
than code using integers on the stack.
- When variables on the stack go out of scope, their
corresponding objects on the heap are dereferenced,
not destroyed.
- The .NET Framework eventually starts a process called
Garbage Collection and deallocates all dereferenced
objects on the heap.
Value types
- Value types store their value directly
- Value types can exist on the stack and the heap
- Value types are assigned by value
- Value types are compared by value
Reference types
- Reference types can be set to null
- Reference type store a reference to a value on the heap
- Reference types can exist on the stack and the heap
- Reference types are assigned by reference
- Reference types are compared by reference
Boxing and unboxing
- Boxing takes a value type on the stack and stores it as an
object on the heap
- Boxing happens when you assign a value type to a variable,
parameter, field or property of type object
- Unboxing unpacks a boxed object on the heap, and copies
the value type inside back to the stack
- Unboxing happens when you cast an object value to a value
type
- Boxing and unboxing negatively affect performance
Immutable strings
- Strings are reference types, and immutable
- Strings behave as if they are value types. They are assigned
and compared by value
- Strings are thread-safe
- Strings are fast
- Strings conserve memory
Intermediate Language
- JIT compilation optimises for local hardware
- IL code is portable, can be verified and annotated
- IL uses local variable locations and an evaluation stack
- Built-in support for objects
- Built-in support for 1-dimensional arrays

You might also like