# Basics of Java Garbage Collection

DevFeed: [Basics of Java Garbage Collection](<https://devfeed.tech/articles/basics-of-java-garbage-collection-24980.md>)

Original publisher: [Read original article](<https://codeahoy.com/2017/08/06/basics-of-java-garbage-collection/>)

Author: umer

Published: 2017-08-06T00:00:00Z

Content type: tutorial

Language: en

Sources: [Code Ahoy - Articles](<https://devfeed.tech/sources/code-ahoy-articles.md>)

Topics: [Java](<https://devfeed.tech/topics/java.md>), [Algorithms](<https://devfeed.tech/topics/algorithms.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [real-time](<https://devfeed.tech/topics/real-time.md>)

Tags: [garbage-collection](<https://devfeed.tech/tags/garbage-collection.md>), [garbage-collectors](<https://devfeed.tech/tags/garbage-collectors.md>), [gc](<https://devfeed.tech/tags/gc.md>), [hotspot](<https://devfeed.tech/tags/hotspot.md>), [java](<https://devfeed.tech/tags/java.md>), [jvm](<https://devfeed.tech/tags/jvm.md>), [latency](<https://devfeed.tech/tags/latency.md>), [low-latency](<https://devfeed.tech/tags/low-latency.md>), [memory](<https://devfeed.tech/tags/memory.md>), [performance](<https://devfeed.tech/tags/performance.md>), [real-time](<https://devfeed.tech/tags/real-time.md>), [threads](<https://devfeed.tech/tags/threads.md>), [troubleshooting](<https://devfeed.tech/tags/troubleshooting.md>)

## AI overview

This tutorial provides a high-level overview of Java garbage collection, including collector algorithms, stop-the-world pauses, throughput and low-latency tradeoffs, JVM heap generations, and troubleshooting performance issues.

## Source excerpt

Knock, knock. Who's there? ...long GC pause... Java. It's an old joke from the time when Java was new and slow compared to other languages. Over time, Java became a lot faster. Today it powers many real-time applications with hundreds of thousands of concurrent users. These days, the biggest impact on Java's performance comes from its garbage collection. Fortunately, in many cases, it can be tweaked and optimized to improve performance. For most applications, the default settings of the JVM work fine. But when you start noticing performance issues caused by garbage collection and giving more heap memory isn't possible, you need to tune and optimize the garbage collection. For most developers, it's a chore. It requires patience, good knowledge of how garbage collection works and an understanding of application's behavior. This post is a high-level overview of Java's garbage collection with some examples of troubleshooting performance issues. Let's get started. Java ships with several garbage collectors. More specifically, these are different algorithms that run in their own threads. Each works differently and has pros and cons. The most important thing to keep in mind is that all garbage collectors stop the world. That is, your application is put on hold or paused, as the garbage is collected and taken out. The main difference among the algorithms is how they stop the world. Some algorithms sit completely idle until the garbage collection is absolutely needed and then pause your application for a long period while others do most of their work concurrently with your application and thus need a shorter pause during stop the world phase. The best algorithm depends on your goals: are your optimizing for throughput where long pauses every now and then are tolerable or you are optimizing for low latency by spreading it out and having short pauses all along. To enhance the garbage collection process, Java (HotSpot JVM, more accurately) divides up the heap memory into two genera