0% found this document useful (0 votes)
28 views12 pages

Memory Management: The Stack & The Heap

The document discusses memory management concepts in .NET including the stack, heap, value types, reference types, boxing and unboxing. It explains that the stack uses LIFO for value types and the heap uses FIFO for reference types. Common value types like integers are stored on the stack while reference types like classes and objects are stored on the heap with pointers on the stack.

Uploaded by

Mihaela Maxim
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)
28 views12 pages

Memory Management: The Stack & The Heap

The document discusses memory management concepts in .NET including the stack, heap, value types, reference types, boxing and unboxing. It explains that the stack uses LIFO for value types and the heap uses FIFO for reference types. Common value types like integers are stored on the stack while reference types like classes and objects are stored on the heap with pointers on the stack.

Uploaded by

Mihaela Maxim
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/ 12

Memory Management

The Stack & The Heap


LIFO & FIFO

A stack is a LIFO

A queue is a FIFO
Value types and reference types
Value types are placed on the Stack (and sometimes on the Heap)

Reference types are placed on the Heap (and on the stack we have a pointer to
them)
Value types
Enums

DateTime

Int, Double, Float, Short, Long

Bool

Char

All structures created by our application


Enums
a set of named constants

Example:

enum Days {Sat, Sun, Mon, Tue, Wed, Thu, Fri};


Structs
is suitable for representing lightweight objects such

Example
Reference types
String

Object

All classes created by our application


How our code runs in terms of Memory
Function calls are placed on stack

Value type parameters are copied on the stack

Reference type parameters have pointers on the stack


Walk through the code
Walk with value types
Walk through the code
Walk with value & reference types
Boxing and Unboxing
In .NET everything inherits from Object (even value types)

Example and what we have on the Stack and on the Heap


Mutable and Immutable objects
Mutable vs Immutable objects

String is immutable

StringBuilder is mutable

Example how to create a string (class Author)

You might also like