And busting all three of them

Popular myths about Garbage Collection

Ram Lakshmanan
Garbage Collection

© Shutterstock / TungCheung

In this article, Ram Lakshmanan goes over the most popular myths about Garbage Collection. Don’t worry — he’ll also debunk them to make sure you won’t repeat the same mistakes ever again.

There are few very popular myths about Garbage Collection. Let’s review those myths and reveal the truth behind them.

Minor GC don’t pause the application

Myth: There are different types of Garbage Collection events: Minor GC event, Major GC event & Full GC event. It’s been educated that Minor GC are harmless, as they don’t pause the application. However, Major/Full GC are dangerous because they pause the application.

Verdict: This is a lie. 100% lie.

Truth: Minor GC *do pause* the application. Minor GC pause times are comparatively lower than other GC events most of the times, thus they could have been educated as ‘harmless’. However, in some cases, we have seen Minor GC take more time than all the Major/Full GC events.

Therefore, when tuning your application, pay proper attention to Minor GC pause time metrics as well.

SEE ALSO: The proliferation of Java Garbage Collection logs standards

Serial GC performance is horrible

There are several types of Garbage Collection algorithms:

a. Serial GC

b. Parallel GC

c. Concurrent Mark & Sweep (CMS) GC

d. G1 GC

e. Shenandoah GC

Myth: Each GC algorithm exhibits its unique performance characteristics. A false assumption the industry has been making is the following: Serial GCs are not meant for serious applications. Serial GC performance characteristics are horrible and [serial GCs] should be used only during development time or in prototype applications.

To validate this theory, we conducted a study on a major B2B travel application in production, which processes more than 70% of North America’s leisure travel transactions. We configured a couple of servers to use latest ‘G1 GC’ algorithm and couple of servers to use ‘Serial GC’ algorithm. We just used vanilla G1 GC and Vanilla Serial GC settings. We didn’t pass any additional GC tuning parameters. Details about this study can be found here.

Verdict: Serial GC is not as bad as it’s portrayed.

Truth: Results turned out that Serial GC performance to be comparable with (in fact slightly better than) G1 GC algorithm. Of course, with proper tuning & parameters settings, G1 GC can be made to run better than Serial GC. The take away is Serial GC is not as bad as it’s portrayed.

GC is automatic. I don’t have to worry about it.

Myth: I have heard a few developer friends saying: “Garbage Collection is Automatic. I don’t have to worry about it”. The first part is true i.e. “Garbage Collection is Automatic” on all modern platforms – JVM (Java Virtual Machine), ART (Android Run Time) …. But the second part is not so true i.e. “I don’t have to worry about it”. Garbage Collection is automatic, but it’s not free.

Verdict: Garbage Collection is automatic, but it’s not free.

Truth: Garbage Collection comes at a price. In fact, that price can be very high.

Poor Garbage Collection can lead to:

  • Unpleasant user experience (SLA Breaches)
  • Increase in the bill from cloud hosting providers
  • Puts entire application availability under risk

To learn about the profound impact of Garbage Collection, you may want to read this article.

If you want to read more about the open source Z Garbage Collector (ZGC) — designed with the aim to remove obstacles that have previously hindered Java developers from getting access to innovations and new features—, don’t miss this interview


Ram Lakshmanan

Every single day, millions & millions of people in North America—bank, travel, and commerce—use the applications that Ram Lakshmanan has architected. Ram is an acclaimed speaker in major conferences on scalability, availability, and performance topics. Recently, he has founded a startup, which specializes in troubleshooting performance problems.

Inline Feedbacks
View all comments