Quick revision
The short answer
Serial GC collects with a single thread while the application is stopped, which gives it the lowest CPU and memory overhead of all HotSpot collectors. It is the right choice for small heaps, single-CPU containers, command-line tools and short-lived processes. The JVM picks it on its own when the machine is not server-class, roughly fewer than two available CPUs or less than about 2 GB of memory, which often happens in small containers; we check the choice in the startup GC log or with jcmd, and select G1 explicitly with -XX:+UseG1GC if we want it.
What to remember
In this answer, we saw that Serial GC is a single-threaded stop-the-world collector with the lowest overhead and footprint in HotSpot, which makes it a good fit for small heaps, single-CPU containers, tools and short-lived processes. Ergonomics selects it whenever the JVM does not see a server-class machine, roughly fewer than two CPUs or less than about 2 GB, which is common in small containers. We confirm the choice with the startup Using line of -Xlog:gc or jcmd VM.flags, and we override it with -XX:+UseG1GC when we need G1.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Serial GC collects with a single thread while the application is stopped, which gives it the lowest CPU and memory overhead of all HotSpot collectors. It is the right choice for small heaps, single-CPU containers, command-line tools and short-lived processes. The JVM picks it on its own when the machine is not server-class, roughly fewer than two available CPUs or less than about 2 GB of memory, which often happens in small containers; we check the choice in the startup GC log or with jcmd, and select G1 explicitly with -XX:+UseG1GC if we want it.
Why this question is asked
Many teams believe their services run G1 because G1 is the default, and then find out from a GC log that a container with one CPU has been running Serial all along. That is not necessarily a problem, but it is a surprise, and surprises in production are what interviewers want us to be able to explain. In this answer, we will recap what Serial GC does, see where it is the best tool, look at the ergonomics rule that selects it automatically, check which collector a JVM is actually using, and see how to override the choice.
1A Quick Recap of Serial GC
Serial GC is the oldest and simplest collector in HotSpot. It is generational: new objects go into the young generation, and objects that survive a few collections are promoted to the old generation. A young collection copies the live young objects into a survivor space or into the old generation. A full collection marks the whole heap and compacts it, sliding live objects together so free space is one contiguous block.
Everything happens on one GC thread, and the application is stopped for the whole collection. This is called stop-the-world. There are no concurrent phases, no background threads and almost no bookkeeping beyond a card table. The write barrier is a single byte store.
2Where Serial GC Is the Right Choice
Serial's weakness is that pause time grows with the amount of live data, because one thread does all the work. On a 100 MB heap that does not matter: a young collection might take a few milliseconds, and even a full collection stays well under a second. On a 16 GB heap a full collection with one thread could take many seconds.
Its strength is that it costs almost nothing when it is not running. There are no extra GC threads competing for the CPU, no remembered sets taking memory, and the barrier is the cheapest one there is. On a container with one CPU, a parallel or concurrent collector cannot run GC threads alongside the application anyway, because there is only one CPU to share.
So Serial suits small heaps (up to a few hundred megabytes), single-CPU containers, command-line tools, build helpers, short-lived jobs and sidecars. For a process that lives for five seconds, startup and footprint matter more than pause times, and Serial starts fastest and uses the least memory.
| Situation | Serial a good fit? | Why |
|---|---|---|
| CLI tool or short script | yes | smallest footprint, fast startup |
| Sidecar with 1 vCPU, 256 MB | yes | no CPU to spare for GC threads |
| Lambda-style short function | usually | process ends before pauses add up |
| REST API, 4 GB heap, 4 CPUs | no | pauses grow with live data, other CPUs idle |
| Large heap, latency target | no | single-threaded full GC can take seconds |
3When the JVM Picks Serial Without Being Told
If we pass no GC flag, HotSpot ergonomics, the code that chooses defaults from the hardware it sees, decides the collector. Since JDK 9 the rule is: on a server-class machine use G1, otherwise use Serial. A machine is server-class when it has at least two available processors and at least about 2 GB of physical memory; the exact memory threshold is slightly below 2 GB in the source, so treat 2 GB as the rule of thumb.
The important word is available. Since container support arrived in JDK 10 and was backported to JDK 8u191, the JVM reads the CPU and memory limits from the container's cgroup. A Kubernetes pod with a CPU limit of 1 or a memory limit of 1 GiB looks like a small machine to the JVM, even if the node has 64 cores. So the same image runs G1 on a developer laptop and Serial in a small pod.
OpenJDK has discussed making G1 the default in every environment, including small ones, in a release after JDK 25. If you are on a newer JDK, check your version's release notes before relying on this rule.
4Checking Which Collector Is Running
The quickest check is the first GC log line. With -Xlog:gc the JVM prints the collector at startup. For a running process, jcmd shows the flags that ergonomics chose.
We can also run java -XX:+PrintFlagsFinal -version and look at the UseSerialGC, UseG1GC, UseParallelGC and UseZGC lines, and the JMX GarbageCollectorMXBean names tell the same story: Serial reports Copy and MarkSweepCompact. Checking this once per deployment environment is a good habit.
5Selecting the Collector Explicitly
If we want G1 in a small container, for example because the service has a 1.5 GB heap and a latency target, we say so with -XX:+UseG1GC. Explicit selection always wins over ergonomics. Equally, a tool that we know is small can ask for Serial explicitly with -XX:+UseSerialGC, so it behaves the same everywhere.
There is a subtle point with one CPU. G1 can run there, but its concurrent marking and refinement threads now share the single CPU with the application, so the application slows down while they work. For a truly tiny service, Serial may still give better latency and throughput than G1. The honest answer is to measure both on the real container size.
6Follow-up questions
Why might the same image use different collectors in staging and production?
Because ergonomics looks at the container limits, not at the image. If staging pods get 1 CPU and 1 GiB to save money and production pods get 4 CPUs and 8 GiB, staging is not server-class and runs Serial, while production runs G1. Heap size defaults differ too, since the default maximum heap is a quarter of available memory. Latency and GC behaviour measured in staging then tell us little about production. The fix is to set the collector and heap percentage explicitly, or to give staging the same limits.
Is Serial GC ever used for full collections by other collectors?
Not in modern JDKs. Before JDK 10, G1 fell back to a single-threaded full collection, which behaved much like Serial's. JEP 307 made G1's full collection parallel in JDK 10. Parallel GC has had a parallel full collection for a long time.
How much memory does Serial save compared with G1?
It varies, but G1's remembered sets, extra card bookkeeping and concurrent threads typically add a few percent of the heap plus some native memory, while Serial adds almost nothing beyond the card table. For a 128 MB tool that can be the difference between fitting in a small container or not. Native memory tracking with -XX:NativeMemoryTracking=summary shows the GC portion directly.
7Conclusion
In this answer, we saw that Serial GC is a single-threaded stop-the-world collector with the lowest overhead and footprint in HotSpot, which makes it a good fit for small heaps, single-CPU containers, tools and short-lived processes. Ergonomics selects it whenever the JVM does not see a server-class machine, roughly fewer than two CPUs or less than about 2 GB, which is common in small containers. We confirm the choice with the startup Using line of -Xlog:gc or jcmd VM.flags, and we override it with -XX:+UseG1GC when we need G1.
Open with
Serial GC does all its work on one thread while the application is stopped. It has no concurrent threads, the cheapest write barrier and almost no extra memory, so its overhead is the lowest of all HotSpot collectors, but its pauses grow with the live data because one thread does everything.
Then, if they want more
That makes it the right choice for small heaps of a few hundred megabytes, containers with one CPU, command-line tools, sidecars and short-lived processes, where footprint and startup matter more than pause length. The JVM also chooses it by itself.
Ergonomics uses G1 on a server-class machine, which means at least two available CPUs and roughly 2 GB of memory, and Serial otherwise.
Since the JVM is container-aware, a pod with a CPU limit of one or a 1 GiB memory limit counts as a small machine, so the same image can run G1 on my laptop and Serial in production. I check it with the first line of -Xlog:gc, which says Using Serial or Using G1, or with jcmd pid VM.flags.
If I want G1 in a small container I set -XX:+UseG1GC explicitly, and I usually set the collector explicitly anyway so staging and production behave the same.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 10, Java 25, Java 9
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- HotSpot Garbage Collection Tuning Guide, JDK 21
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "When is Serial GC the right choice, and when does the JVM select it without being told?": https://scrivio-interview-library.netlify.app/java/garbage-collection/6c3d7a7785/