We may earn an affiliate commission when you visit our partners.
Course image
Dmitry Soshnikov

Essentials of Garbage Collectors

Read more

Essentials of Garbage Collectors

Memory leaks and dangling pointers are the main issues of the manual memory management. You delete a parent node in a linked list, forgetting to delete all its children first — and your memory is leaking. You delete an object chain in correct order — but suddenly your program crashes since you forgot about second owner of this resource, which now tries to dereference a null-pointer.

To avoid these issues, most of the modern high-level programming languages implement automatic memory management. You allocate objects manually, however don’t bother with their deallocation: a special program, garbage collector, knows how to automatically deallocate them correctly, and reclaim for future reuse.

In the Essentials of Garbage Collectors class we study all different techniques and algorithms related to the automatic memory management, which are used today on practice.

Who this class is for?

First of all, for compiler engineers.

In implementing your programming language, there is a very high chance you’ll need to implement a garbage collector. Even languages which initially were positioned as “memory-safe”, such as Rust, eventual implemented automatic reference counting (ARC) and other collectors.

To reiterate: in most of the modern high-level programming languages, a garbage collector module (or multiple GC modules, like in Java) is pretty much a requirement today.

What if I don't implement programming languages every day?

If you are not a compiler engineer, then the class can still be interesting for you. Implementing a garbage collector or a memory manager in general, is a pretty advanced engineering task. It's a simple trick: you take some complex project (such as a garbage collector, compiler, interpreter, etc), and while building it, you learn all different data structures and algorithms. And then come back to "every-day programming", improved as a better engineer, with the transferable generic knowledge of complex systems.

Do I need C or C++ for this project?

Not really. Of course, C and C++ are probably the best languages for raw memory manipulations and fit well here, however in the course we study generic design algorithms and focus mainly on theoretical aspects of garbage collectors and memory allocators. This means you can implement them in any language you want. For example, you can allocate an `ArrayBuffer` in JavaScript for a virtual heap, or similarly `bytearray` in Python, Rust, etc.

Most of the algorithms in the course are described in generic pseudo-code, so you can port them to any language.

What's specific in this class?

The main things of these lectures are:

  • Concise and straight to the point. Each lecture is self-sufficient, concise, and describes information directly related to the topic, not distracting on unrelated materials or talks.

  • Animated presentation combined with live-editing notes. This makes understanding of the topics easier, and shows how (and when at time) the object structures are connected. Static slides simply don’t work for a complex content.

Reading materials

As further reading and additional literature for this course the following books are recommended:

  • The Garbage Collection Handbook: The Art of Automatic Memory Management by Antony Hosking, Eliot Moss, and Richard Jones

  • The Compiler Design Handbook: Optimizations and Machine Code generation by Y.N. Srikant, Priti Shankar

Enroll now

What's inside

Learning objectives

  • Algorithms and data structures behind automatic memory management in computer programs.
  • Memory management history: static, stack, heap allocations
  • Virtual memory and memory layout
  • Tracing vs. direct collectors
  • Semantic vs. syntactic garbage
  • Mark-sweep garbage collector
  • Mark-compact collector
  • Reference counting collector
  • Copying collector
  • Generational collector
  • Parallel, incremental, concurrent collectors
  • Tri-color abstraction and marking
  • Gc barriers
  • Show more
  • Show less

Syllabus

Learn about memory management history. Understand static, stack, and heap allocations. Known memory leaks and dangling pointer issues. Known virtual memory and memory layout. Build memory allocator.
Read more

You will learn:

  • Static, Stack, Heap allocations

  • Compile vs. Runtime allocation

  • Fixed size vs. Dynamic size allocation

  • Recursion

  • Stack frame

  • Stack overflow

  • Memory leaks, dangling pointers

You will learn:

  • Memory leaks: forget to deallocate

  • Dangling pointers: deallocate too early

  • Human factor in memory management

You will learn:

  • Memory alignment

  • Object header

  • Collector meta-information

You will learn:

  • Virtual address space

  • Kernel space vs. User space

  • Code segment, data segment

  • Stack and stack pointer

  • Heap and break pointer

  • Memory mapping

  • Memory management unit (MMU)

  • Translation lookaside buffer (TLB)

You will learn:

  • Life cycle of a GC'ed program

  • Mutator: user program

  • Allocator: memory allocation

  • Collector: garbage collector

  • Mutator vs. Collector object graph view

  • "Stop the World" state

  • System calls to invoke GC from Mutator

You will learn:

  • Sequential (aka "Bump") allocator

  • Free-list allocator

  • First fit, Next-fit, Best-fit searches

  • Segregated list

  • Blocks coalescing and splitting

  • Lab session to implement `malloc` and `free`

Lab session and example of implementation: http://dmitrysoshnikov.com/compilers/writing-a-memory-allocator/

You will learn:

  • Semantic: objects that will not be reached

  • Syntactic: object that cannot be reached

  • Example of Stack structure

  • Example of invalidated cache

Understand Tracing, and Direct collectors. Mark-Sweep collector algorithm. Mark-Compact collector (Lisp 2). Reference counting collector. Copying Semi-Space collector.

You will learn:

  • Tracing: trace for alive objects

  • Direct: directly identify the garbage

  • Main four collection algorithms

You will learn:

  • Mark phase: objects trace

  • Sweep phase: reclamation

  • Detailed algorithm description with code example

  • Non-moving collector

  • Free-list allocation

  • Heap fragmentation

Example of implementing a Mark-Sweep GC in C++: http://dmitrysoshnikov.com/compilers/writing-a-mark-sweep-garbage-collector/

You will learn:

  • Mark phase: objects trace

  • Compact phase: objects relocation

  • Fixing fragmentation issue

  • Moving collector

  • Forwarding address

  • Lisp 2 algorithm detailed description

  • Sequential allocator

You will learn:

  • Semi-space collector

  • Heap reservation

  • Forwarding address

  • Objects evacuation

  • Fixing child pointers

  • Bump-allocator

  • Detailed algorithm description with code example

You will learn:

  • Directly identify the garbage

  • Strong vs. Weak references

  • Deeply integrated into Mutator

  • Barrier pointer operations

  • Pauses on deep nested structures removal

  • Cyclic references

  • Detailed algorithm description with code example

Learn about generational, parallel, incremental, and concurrent collectors. Understand GC Read- and Write-barriers. Learn Snapshot-at-Beginning, Incremental Update, Bake's and Brooks methods.

You will learn:

  • Heap partitioning

  • Young vs. Old generations

  • Minor vs. Major collection cycles

  • Objects promotion

  • Intergenerational pointers

  • Write barrier

You will learn:

  • Mark-Region collector

  • Mark-Sweep + Copying + Heap partitioning

  • Immix collector

  • Heap segregation: Blocks and Lines

  • Free, Recyclable, Occupied blocks

  • Bump-allocation in recyclable blocks

  • Sweep-to-region technique

  • Heap defragmentation

  • Evacuation from Source to Destination blocks

You will learn:

  • "Stop the World" state

  • Multiple collection threads

  • Collector interruption by Mutator

  • Concurrently running collection thread

  • Synchronization barriers

You will learn:

  • Black, Gray, and White objects

  • Collection time slices

  • Illegal BW-pointers

  • Legal BW-pointers

  • GC barriers

You will learn:

  • Illegal BW-pointers

  • Read and Write barriers

  • Snapshot-at-Beginning

  • Incremental update (Dijkstra and Steel's)

  • Baker's Copying method

  • Brook's method

  • Final notes

In this part we discuss some specific collector types, such as G1 garbage collector from HotSpot virtual machine.
  • Java and HotSpot VM

  • Different GC types in Java

  • Generational collector

  • Minor and Major collection cycles

  • Intergenerational pointers

  • Write barrier

  • Card table

  • CMS heap layout

  • G1 heap layout

  • Region-based collection

  • Eden, Survivor, Old and Humongous regions

  • Stop The World state

  • Parallel collectors

  • Evacuation and promotion

  • Concurrent marking

  • Tri-color abstraction

  • GC barriers

  • Snapshot-at-beginning barrier

  • Mixed GC cycle

Good to know

Know what's good
, what to watch for
, and possible dealbreakers
Explores essential techniques and algorithms in Automatic Memory Management, a core skill in programming
Develops a solid understanding of memory management history and virtual memory, foundational knowledge for software engineers
Led by instructor Dmitry Soshnikov, an authority on compiler engineering, ensuring a high-quality learning experience
Provides a practical approach to memory management, including opportunities for learners to implement allocators and garbage collectors
Covers various garbage collection algorithms, empowering learners with a comprehensive understanding of the field
May require learners to come in with some programming and systems background knowledge

Save this course

Save Garbage Collection Algorithms to your list so you can find it easily later:
Save

Reviews summary

Course recommended

According to students, Garbage Collection Algorithms is full of clear and engaging presentations. The use of illustrations and animations make this course a very popular choice for students.
Animations make lessons come to life.
"Animations help illustrate what is being said."
Presentation are clear and well-paced.
"Very nice and clear presentation"
"Illustrations make it easy to understand the concepts."

Activities

Be better prepared before your course. Deepen your understanding during and after it. Supplement your coursework and achieve mastery of the topics covered in Garbage Collection Algorithms with these activities:
Review Memory Management Concepts
Review fundamental memory management concepts to strengthen the foundation for learning garbage collection.
Browse courses on Memory Management
Show steps
  • Recall and summarize the core concepts of memory management
  • Refresh your understanding of topics such as memory allocation, deallocation, and memory leaks
Review Data Structures and Algorithms for Garbage Collectors
Review essential data structures and algorithms used in garbage collectors to enhance understanding.
Browse courses on Data Structures
Show steps
  • Identify and list the key data structures and algorithms used in garbage collectors
  • Review the concepts and implementation details of each data structure and algorithm
  • Solve practice problems or coding exercises involving these data structures and algorithms
Guided Tutorials on Memory Management Best Practices
Follow guided tutorials to learn and apply best practices in memory management.
Browse courses on Memory Management
Show steps
  • Search for online tutorials on memory management best practices
  • Select a tutorial that aligns with your learning objectives
  • Follow the steps and instructions in the tutorial
  • Apply the best practices in your own code
Six other activities
Expand to see all activities and additional details
Show all nine activities
Memory Allocator
Implement a memory allocator to better understand the memory management concepts.
Browse courses on Memory Management
Show steps
  • Design and plan your memory allocator
  • Implement the basic functionality of the memory allocator
  • Test and debug your memory allocator
  • Optimize your memory allocator for performance
Review 'The Garbage Collection Handbook: The Art of Automatic Memory Management'
Review the concepts of automatic memory management which are covered in the course.
Show steps
  • Read the introduction to the book
  • Read a chapter of the book relating to the topics you are most interested in
  • Practice the exercises in the book to test your understanding
  • Summarize the key concepts of the book
Garbage Collector Algorithm Implementation
Practice implementing various garbage collector algorithms to solidify knowledge and skills.
Browse courses on Garbage Collection
Show steps
  • Choose a garbage collector algorithm to implement
  • Design and plan the implementation of the algorithm
  • Code the implementation of the algorithm
  • Test and debug the implementation
  • Evaluate and improve the implementation
Presentation on Garbage Collection Algorithms
Create a presentation to summarize and present the various garbage collection algorithms covered in the course.
Browse courses on Garbage Collection
Show steps
  • Select the garbage collection algorithms to cover in your presentation
  • Research and gather information about each algorithm
  • Design and structure your presentation
  • Create the content for your presentation
  • Practice and rehearse your presentation
Attend a Workshop on Advanced Garbage Collection Techniques
Attend a workshop to enhance your understanding of advanced garbage collection techniques.
Browse courses on Garbage Collection
Show steps
  • Search for and identify a relevant workshop
  • Register for the workshop
  • Attend the workshop and actively participate
  • Take notes and ask questions during the workshop
Contribute to Open Source Garbage Collection Projects
Contribute to open source garbage collection projects to apply and expand your knowledge.
Browse courses on Garbage Collection
Show steps
  • Identify open source garbage collection projects to contribute to
  • Review the documentation and codebase of the project
  • Select an area or issue to work on
  • Make changes and submit pull requests

Career center

Learners who complete Garbage Collection Algorithms will develop knowledge and skills that may be useful to these careers:
Compiler Engineer
Compiler Engineers are responsible for designing, developing, and maintaining compilers that translate high-level code into efficient machine instructions. They ensure that compiled programs run smoothly and efficiently on various platforms. The Essentials of Garbage Collectors course is highly relevant to this role, as it delves into the intricacies of automatic memory management in compilers. By understanding how garbage collectors operate, you can contribute to the development of advanced compilers that optimize memory usage and improve program performance.
Memory Manager
Memory Managers specialize in optimizing memory usage and performance in computer systems. They develop and implement memory management algorithms and techniques to maximize memory efficiency and minimize memory leaks. The Essentials of Garbage Collectors course is highly relevant to this role, as it provides a comprehensive understanding of various garbage collection algorithms, including mark-sweep, mark-compact, and reference counting. By gaining expertise in these techniques, you can pursue a career as a Memory Manager and excel in optimizing memory management systems.
Performance Engineer
Performance Engineers analyze and optimize the performance of computer systems and applications. They identify bottlenecks and inefficiencies, and implement solutions to improve system performance and user experience. The Essentials of Garbage Collectors course can benefit Performance Engineers by providing insights into memory management techniques and their impact on system performance. By understanding how garbage collection works, you can identify memory-related performance issues and develop strategies to mitigate them, ensuring optimal system performance under various workloads.
Virtualization Engineer
Virtualization Engineers specialize in creating and managing virtual environments, enabling multiple operating systems and applications to run simultaneously on a single physical server. They ensure that virtual machines operate efficiently and securely. The Essentials of Garbage Collectors course can provide valuable knowledge for Virtualization Engineers, as it covers memory management techniques in virtualized environments. By understanding how garbage collection works in virtual machines, you can optimize memory usage, improve performance, and prevent memory-related issues, ensuring the smooth operation of your virtualized systems.
Cloud Architect
Cloud Architects design and manage cloud computing systems, ensuring scalability, reliability, and cost-effectiveness. They work with organizations to develop and implement cloud strategies, optimizing cloud resource utilization. The Essentials of Garbage Collectors course can provide Cloud Architects with a solid foundation in memory management techniques in cloud environments. By understanding how garbage collection operates in cloud platforms, you can design and manage cloud systems that are efficient, scalable, and cost-optimized.
Systems Engineer
Systems Engineers design, deploy, and maintain complex computer systems and networks. They ensure that these systems operate reliably and efficiently, meeting the organization's business needs. The Essentials of Garbage Collectors course can be beneficial for Systems Engineers, providing insights into memory management techniques in operating systems and virtual machines. By understanding how garbage collection works, you can enhance the stability and performance of the systems you manage, ensuring smooth operation and optimal resource utilization.
Computer Scientist
Computer Scientists play a pivotal role in designing and developing computer hardware, software, and systems, providing innovative solutions to real-world issues. They use their expertise in algorithms, data structures, and computer languages to solve complex problems. The Essentials of Garbage Collectors course can be a valuable asset for aspiring Computer Scientists, providing a comprehensive understanding of automatic memory management algorithms and techniques. By studying memory allocation and deallocation, you'll gain fundamental programming concepts that will enhance your ability to develop efficient and reliable software applications.
Software Engineer
Software Engineers apply their programming skills to design, develop, test, and maintain software systems. They work on a wide range of projects, from developing mobile apps to building complex enterprise systems. The Essentials of Garbage Collectors course can provide Software Engineers with an in-depth understanding of memory management techniques, enabling them to write clean and efficient code. By mastering these concepts, you can improve the performance and reliability of your software applications.
DevOps Engineer
DevOps Engineers bridge the gap between development and operations teams, ensuring smooth collaboration and efficient software delivery. They automate and streamline software development and deployment processes. The Essentials of Garbage Collectors course may be useful for DevOps Engineers who work on projects involving continuous integration and continuous delivery pipelines. By understanding memory management techniques, you can optimize memory usage and prevent memory leaks, ensuring the smooth and reliable deployment of software applications.
Embedded Systems Engineer
Embedded Systems Engineers design and develop computer systems for embedded devices such as smartphones, industrial controllers, and medical equipment. They ensure that these systems meet strict requirements for performance, reliability, and power consumption. The Essentials of Garbage Collectors course may be useful for Embedded Systems Engineers who work on systems with limited memory resources. By understanding memory management techniques, you can optimize memory usage and minimize memory leaks, which is crucial for ensuring the smooth operation of embedded systems with constrained resources.
Quality Assurance Engineer
Quality Assurance Engineers test and evaluate software applications to ensure they meet quality standards and user requirements. They work on various aspects of software testing, including functional testing, performance testing, and security testing. The Essentials of Garbage Collectors course may be useful for Quality Assurance Engineers who work on testing memory-intensive applications or systems. By understanding memory management techniques, you can identify and debug memory-related issues more effectively, contributing to the delivery of high-quality software products.
Security Engineer
Security Engineers design and implement security measures to protect computer systems and networks from cyber threats. They work on various aspects of cybersecurity, including vulnerability assessment, threat detection, and incident response. The Essentials of Garbage Collectors course may be useful for Security Engineers who work on memory-related security vulnerabilities. By understanding memory management techniques, you can identify and mitigate memory-based attacks, such as buffer overflows and memory leaks, enhancing the security posture of computer systems.
Game Developer
Game Developers design and develop video games, working on various aspects such as gameplay, graphics, and artificial intelligence. They use their programming skills to create immersive and engaging gaming experiences. The Essentials of Garbage Collectors course may be useful for Game Developers who work on complex games with dynamic memory allocation. By understanding memory management techniques, you can optimize memory usage and prevent memory-related crashes, ensuring a smooth and enjoyable gaming experience for users.
Database Administrator
Database Administrators manage and maintain database systems, ensuring data integrity, security, and performance. They work with databases to create, modify, and optimize data structures and storage mechanisms. The Essentials of Garbage Collectors course may be useful for Database Administrators who work on large and complex databases with dynamic data allocation. By understanding memory management techniques, you can optimize memory usage and prevent memory-related issues, ensuring the smooth operation and performance of database systems.
Data Analyst
Data Analysts collect, analyze, and interpret data to extract meaningful insights. They use statistical and programming skills to identify trends, patterns, and relationships in data. The Essentials of Garbage Collectors course may be useful for Data Analysts who work on data-intensive projects, particularly those involving large datasets. By understanding memory management techniques, you can optimize memory usage and prevent memory leaks, ensuring the efficient processing and analysis of large datasets.

Reading list

We've selected 14 books that we think will supplement your learning. Use these to develop background knowledge, enrich your coursework, and gain a deeper understanding of the topics covered in Garbage Collection Algorithms.
Is the definitive guide to garbage collection and is highly recommended for anyone who wants to learn more about this topic. It covers all the major garbage collection algorithms and techniques in depth, and it is written in a clear and concise style.
Classic work on computer science. It includes a chapter on memory management, which valuable resource for anyone who wants to learn more about garbage collection.
Classic work on algorithms. It includes a chapter on memory management, which valuable resource for anyone who wants to learn more about garbage collection.
Provides a comprehensive overview of computer systems, including a chapter on memory management. This chapter provides a good introduction to the topic, and it useful resource for anyone who wants to learn more about garbage collection.
Provides clear explanations for many algorithms useful in a garbage collection implementation, e.g. mark-sweep, reference counting, and mark-compact.
Provides a comprehensive overview of data structures and algorithms in C++. It includes a chapter on memory management, which valuable resource for anyone who wants to learn more about garbage collection.
Provides a comprehensive overview of data structures and algorithms in Java. It includes a chapter on memory management, which valuable resource for anyone who wants to learn more about garbage collection.
Comprehensive introduction to data structures and algorithm analysis in Java. It includes a chapter on memory management, which valuable resource for anyone who wants to learn more about garbage collection.
Provides a comprehensive overview of JavaScript. It includes a chapter on memory management, which valuable resource for anyone who wants to learn more about garbage collection.
Provides practical advice on how to write efficient and reliable code in C. It includes a chapter on memory management, which valuable resource for anyone who wants to learn more about garbage collection.
Fun and engaging way to learn about data structures and algorithms. It includes a chapter on memory management, which valuable resource for anyone who wants to learn more about garbage collection.
Concise and practical guide to algorithms. It includes a chapter on memory management, which valuable resource for anyone who wants to learn more about garbage collection.
Has a section on memory management, which provides a broad overview of the topic. It useful resource for anyone who wants to learn more about garbage collection.

Share

Help others find this course page by sharing it with your friends and followers:

Similar courses

Here are nine courses similar to Garbage Collection Algorithms.
IDisposable Best Practices for C# Developers
Most relevant
Understanding the Java Virtual Machine: Memory Management
Most relevant
Build a Guessing Game Application using Java
Most relevant
Julia 1: Getting Started
Compilers
What's New in Java 10: Local-variable Type Inference
Crash Course Digital Electronics
C Programming: Modular Programming and Memory Management ...
Understanding and Solving Java Memory Problems
Our mission

OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.

Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.

Find this site helpful? Tell a friend about us.

Affiliate disclosure

We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.

Your purchases help us maintain our catalog and keep our servers humming without ads.

Thank you for supporting OpenCourser.

© 2016 - 2024 OpenCourser