Garbage collection
Garbage collection automatically frees memory for reuse when a running program can no longer reach the data stored there (Wilson, 1992). In Java benchmarks, collection costs varied with the memory available, and shorter collection pauses sometimes came with slower application responses (Blackburn et al., 2025; Cai et al., 2022).
Tracing and reference counting
Tracing follows references from a set of roots. A reference is a link to a stored object, and roots are the starting references available to the running program. A mark-and-sweep collector marks every object it reaches, then reclaims the space occupied by unmarked objects (Wilson, 1992). John McCarthy’s 1960 account of Lisp described tracing storage from a set of registers that served as roots (McCarthy, 1960).
Reference counting keeps a tally of how many references point to each object. When the tally reaches zero, the collector can reclaim the object’s memory (Wilson, 1992). George Collins described using such counts in 1960 to reclaim storage shared among linked lists (Collins, 1960).
Suppose two objects refer to each other and the program drops its last reference to either of them. Each object’s count stays at one, so basic reference counting leaves both objects in memory. Both objects are unreachable from the roots of a tracing collector, which can reclaim them (Wilson, 1992).
Generations and concurrent collection
Generational collection groups objects by age so the collector can examine younger objects more often. Collecting a smaller region more frequently limits repeated work on objects that live a long time (Wilson, 1992). Henry Lieberman and Carl Hewitt proposed a design in 1983 that made storage for short-lived objects cheaper than storage for long-lived objects (Lieberman & Hewitt, 1983). The Generational ZGC design for the Java Virtual Machine also keeps younger and older objects in separate generations (Vidstedt, 2023).
Concurrent collection lets the program keep running during some of the collector’s work. Edsger Dijkstra and colleagues described a design in 1978 that ran most collection work on a separate processor while computation continued (Dijkstra et al., 1978).
Memory, execution time and responsiveness
The measured cost depends on the heap size and the basis for comparison. The heap is the memory where the program allocates objects. When less heap space was available, collection used more processor time in tests of five OpenJDK 21 collectors across 22 DaCapo Chopin benchmarks (Blackburn et al., 2025).
| Benchmark comparison | Baseline | Result |
|---|---|---|
| One generational collector in simulated Java runs | Simulated explicit allocation and freeing, with objects freed when they became unreachable | The collector, which used a non-copying older generation, matched the baseline’s performance at five times the baseline’s memory (Hertz & Berger, 2005). |
| Five OpenJDK 17 collectors across 16 DaCapo benchmarks | An estimate of the time each application needed to do its own work | Estimated minimum extra elapsed time ranged from 7% to 82% across collectors. The study combined each collector’s results across benchmarks using a geometric mean, a way to average ratios. Each benchmark ran with 2.4 times the smallest heap it could use with the G1 collector (Cai et al., 2022). |
Application latency is the time between a request for work and the application’s response. A collection pause is time when the collector stops the application from running. In the OpenJDK 17 tests, collectors designed to shorten pauses sometimes produced longer application response times than collectors that stopped the application to collect (Cai et al., 2022).
Further reading
- Wilson (1992) surveys tracing, reference counting and collection by generation.
- Dijkstra et al. (1978) presents an early design for running collection alongside a program.
- Cai et al. (2022) compares elapsed time and application latency across production Java collectors.
First published .
Known gaps
What this article cannot tell you yet.
- The performance comparisons cover selected Java workloads. The size of these trade-offs in other runtimes and in deployed services remains open.
References
- Solid source
- Rated highly trustworthy by the research, and every passage taken from it was found in it.
- Weak source
- Rated low, or a passage taken from it was not found in it.
- Medium trust
- Rated medium by the research.
- Not checked
- Rated high, but its passages could not all be checked against it.
Show all 9 references
- Blackburn, S. M., Cai, Z., Chen, R., Yang, X., Zhang, J., & Zigman, J. (2025). Rethinking Java performance analysis. Proceedings of the 30th ACM International Conference on Architectural Support for Programming Languages and Operating Systems, Volume 1. https://www.steveblackburn.org/pubs/papers/dacapo-asplos-2025-with-appendix.pdf Solid source Peer-reviewed, read in large part.
- Cai, Z., Blackburn, S. M., Bond, M. D., & Maas, M. (2022). Distilling the real cost of production garbage collectors. IEEE International Symposium on Performance Analysis of Systems and Software, 46–57. https://www.steveblackburn.org/pubs/papers/lbo-ispass-2022.pdf Solid source Peer-reviewed, read in large part.
- Collins, G. E. (1960). A method for overlapping and erasure of lists. Communications of the ACM, 3(12), 655–657. https://osm.hpi.de/pt2/2018/PDF/Unit03-Freispeicherverwaltung.pdf Medium trust Peer-reviewed, read in large part.
- Dijkstra, E. W., Lamport, L., Martin, A. J., Scholten, C. S., & Steffens, E. F. M. (1978). On-the-fly garbage collection: An exercise in cooperation. Communications of the ACM, 21(11), 966–975. https://www.microsoft.com/en-us/research/wp-content/uploads/2016/12/On-the-fly-Garbage-Collection.pdf Solid source Peer-reviewed, read in large part.
- Hertz, M., & Berger, E. D. (2005). Quantifying the performance of garbage collection vs. explicit memory management. ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA). https://www.cs.tufts.edu/comp/150BUGS/gcvsmalloc-2005.pdf Solid source Peer-reviewed, read in large part.
- Lieberman, H., & Hewitt, C. (1983). A real-time garbage collector based on the lifetimes of objects. Communications of the ACM, 26(6), 419–429. https://www.cs.tufts.edu/comp/250RTS/archive/carl-hewitt/generational-gc.pdf Solid source Peer-reviewed, read in large part.
- McCarthy, J. (1960). Recursive functions of symbolic expressions and their computation by machine, Part I. Communications of the ACM, 3(4), 184–195. https://www.cs.tufts.edu/comp/150FP/archive/john-mccarthy/recursive.pdf Solid source Peer-reviewed, read in large part.
- Vidstedt, M. (2023). Generational Z Garbage Collector. Oracle CloudWorld. https://static.rainfocus.com/oracle/cwoh23/sess/1686591950248001yCz5/finalsessionfile/2023-09-13-2%20-%20LRN3834%20-%20Generational%20Z%20Garbage%20Collector_1694635407855001J5YO.pdf Weak source Vendor page, read in large part.
- Wilson, P. R. (1992). Uniprocessor garbage collection techniques. International Workshop on Memory Management, 1–42. https://condor.depaul.edu/dmumaugh/readings/handouts/CSC548/gcsurvey.pdf Medium trust Peer-reviewed, read in large part.