Inferensys

Glossary

Garbage Collection

An automated process that reclaims storage space within a container registry by deleting unreferenced or untagged image manifests and orphaned layer blobs.
Developer building agentic RAG system, retrieval pipeline diagram on laptop, technical workspace with notes.
REGISTRY MAINTENANCE

What is Garbage Collection?

Garbage collection is an automated process that reclaims storage space within a container registry by deleting unreferenced or untagged image manifests and orphaned layer blobs.

Garbage collection is the automated process of identifying and deleting orphaned layer blobs and unreferenced manifests in a container registry. Because registries use content-addressable storage, layers are shared across multiple image tags. When a tag is deleted or overwritten, the underlying layers are not immediately removed, as they may still be referenced by other manifests. The garbage collector performs a mark-and-sweep operation, traversing all reachable manifests and deleting any blobs not associated with a current reference.

In air-gapped and private container registries, garbage collection is critical for managing storage quotas and reducing costs. Without it, continuous integration pipelines that push frequent builds with unique tags rapidly consume terabytes of disk space. The process is typically invoked manually or on a schedule via the registry's administration API, and it must be executed during a read-only maintenance window to prevent race conditions with concurrent pushes. A properly configured retention policy often complements garbage collection by automatically untagging stale images before the sweep.

GARBAGE COLLECTION

Key Characteristics

The automated process that reclaims storage space within a container registry by deleting unreferenced or untagged image manifests and orphaned layer blobs.

01

Manifest Deletion Logic

Garbage collection identifies manifests that are no longer referenced by any tag. When a tag is overwritten or deleted, the underlying manifest becomes untagged. The GC process scans for these untagged manifests and removes them, breaking the link between the manifest and its associated layers. This is the first phase of a two-phase deletion process.

02

Blob Orphan Detection

After manifests are deleted, the GC process identifies orphaned blobs—filesystem layers that are no longer referenced by any remaining manifest. Because container registries use content-addressable storage, a single blob may be shared across multiple images. GC must perform a mark-and-sweep algorithm to determine which blobs are truly unreachable before deletion.

03

Mark-and-Sweep Algorithm

The standard GC implementation uses a two-phase mark-and-sweep approach:

  • Mark Phase: Traverses all reachable manifests and marks every referenced blob as live.
  • Sweep Phase: Iterates over all stored blobs and deletes any that were not marked. This ensures that shared layers are preserved even when one referencing image is removed.
04

Registry Consistency Locking

During garbage collection, the registry typically enters a read-only mode to prevent race conditions. If a push operation were to upload a new manifest referencing a blob that GC is about to delete, data corruption would occur. Production registries like Harbor and Docker Distribution implement file-level locking or maintenance windows to ensure atomicity.

05

Retention Policy Integration

Garbage collection is often triggered by retention policies that define which images to keep. Policies may specify:

  • Keep the last N versions per repository
  • Retain images deployed in the last 90 days
  • Preserve images with specific immutable tags GC executes the policy decisions by removing everything outside the retention window.
06

Untagged vs. Unreferenced

A critical distinction in GC behavior:

  • Untagged: A manifest with zero associated tags. These are always candidates for deletion.
  • Unreferenced: A manifest that is tagged but not referenced by any running workload. GC does not typically delete these unless a retention policy explicitly targets them. Understanding this distinction prevents accidental deletion of production images.
GARBAGE COLLECTION

Frequently Asked Questions

Essential questions about how container registries reclaim storage space by removing unreferenced manifests and orphaned layer blobs.

Garbage collection is an automated maintenance process that reclaims disk space within a container registry by permanently deleting unreferenced image manifests and orphaned layer blobs that are no longer associated with any tagged or referenced artifact. Unlike a simple file deletion, garbage collection operates on the registry's content-addressable storage model, where blobs are shared across multiple images. The process must first identify which blobs are still reachable through any tag or manifest reference, then safely remove only those blobs that have become completely disconnected from the registry's object graph. This is critical in private registries where CI/CD pipelines generate hundreds of ephemeral builds daily, rapidly consuming terabytes of storage with intermediate layers that are never deployed to production.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.