Heap Memory Management
and Garbage Collection
Photo by
Tom Fisk
from
Pexels
It's time to learn about how the heap works! We've been using
it, and Now we're going to learn about explicit and automatic memory
management---or garbage collection!---for the heap. We're going to see how
those memory-managed languages (like Java!) are making it happen.
Learning Objectives
We will explore heap management algorithms, including those for allocation, and explicit deallocation techniques. We will also explore garbage collection techniques. In particular, we will see how they identify and collect the garbage.
Upon completion of this module, you will be able to:
- Name and describe the categories of heap memory management techniques.
- Describe allocation algorithms and assess the advantages and disadvantages of each.
- Consider free list management and describe optimization techniques.
- Name and describe the algorithmic components of garbage collection algorithms.
- Discuss methods to identify garbage and assess the advantages and disadvantages of each.
- Assess the best approach for an application with a given set of characteristics.
Learning (1 of 2): Heap Memory Management
- Video: The Heap (3 minutes)
- Video: Heap Memory Manager (5 minutes)
- Video: Explicit vs. Automatic Memory Management (7 minutes)
- Video: Bump Pointer Allocator (6 minutes)
- Video: Free List Allocator (8 minutes)
- Video: Free List Performance (3 minutes)
- Video: Free List Deallocation (4 minutes)
-
Slides that were presented in the videos
Learning (2 of 2): Garbage Collection
- Video: Garbage Collection (8 minutes)
- Video: Identifying Garbage (8 minutes)
- Video: Garbage Collection Approaches (5 minutes)
- Video: Mark Sweep (6 minutes)
- Video: Mark Compact (4 minutes)
- Video: Semi Space (6 minutes)
- Video: Generational Collector (7 minutes)
-
Slides that were presented in the videos
Note that these videos have embedded formative assessments---you'll want to watch the videos and complete those before class, so that you can earn participation credit.
Recommended Readings
Completing the readings in this class is highly recommended---it can be very helpful to see how the concepts are explained by a different person, and the extra details can help the pieces fit together.
OSTEP: Memory:API
Fun Insights
- Julia Evan's (@b0rk) Memory Allocation comic
- Think this is really interesting, but sad that we can't move objects for C/C++? Check out: Mesh: Compacting Memory Management for C/C++ Applications
From Class
Evaluating Your Understanding
We are providing these rubrics for each module so that you can better understand what is expected and evaluate your understanding against those expectations. The hope is that, if you find yourself earning a 3 or below, you will continue to enhance your understanding until you find yourself earning a 4 or a 5.
| Standards for Heap Memory Management Sub-Competency | 5 | 4 | 3 | 2 |
|---|---|---|---|---|
| Garbage Collection | Student accurately describes the purpose of garbage collection and the algorithmic components of garbage collection algorithms, accurately assess the advantages and disadvantages of each approach, accurately evaluates and justifies the best approach for an application with a given set of characteristics, and accurately predicts the status of objects in the heap for a particular algorithm given allocation and access patterns. | Student accurately describes the purpose of garbage collection and the algorithmic components of garbage collection algorithms, accurately assess the advantages and disadvantages of each approach, satisfactorily evaluates and justifies the best approach for an application with a given set of characteristics, and satisfactorily predicts the status of objects in the heap for a particular algorithm given allocation and access patterns. | Student satisfactorily describes the purpose of garbage collection and the algorithmic components of garbage collection algorithms, satisfactorily assess the advantages and disadvantages of each approach, but unsatisfactorily evaluates and justifies the best approach for an application with a given set of characteristics, and unsatisfactorily predicts the status of objects in the heap for a particular algorithm given allocation and access patterns. | Student does not submit the work OR student unsatisfactorily describes the purpose of garbage collection and the algorithmic components of garbage collection algorithms, unsatisfactorily assess the advantages and disadvantages of each approach, unsatisfactorily evaluates and justifies the best approach for an application with a given set of characteristics, and unsatisfactorily predicts the status of objects in the heap for a particular algorithm given allocation and access patterns. |
| Short Answer Questions: Heap-Specific | Student submitted answers to given questions that accurately and succinctly answer the questions. | Student submitted answers to given questions that satisfactorily and succinctly answer the questions. | Student submitted answers to given questions that unsatisfactorily answer the questions. | Student does not submit the answers OR submitted answers to given questions that incorrectly answer the questions. |
| Short Answer Questions: Heaps as part of the larger system | Student submitted answers to given questions that accurately and succinctly answer the questions. | Student submitted answers to given questions that satisfactorily and succinctly answer the questions. | Student submitted answers to given questions that unsatisfactorily answer the questions. | Student does not submit the answers OR submitted answers to given questions that incorrectly answer the questions. |