Heap Memory Management
and Garbage Collection

Excavator moves garbage at a landfill 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:

Learning (1 of 2): Heap Memory Management

Learning (2 of 2): Garbage Collection

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

From Class

Slides
Heap Activity

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.