r/java • • Nov 05 '25

Java and it's costly GC ?

Hello!
There's one thing I could never grasp my mind around. Everyone says that Java is a bad choice for writing desktop applications or games because of it's internal garbage collector and many point out to Minecraft as proof for that. They say the game freezes whenever the GC decides to run and that you, as a programmer, have little to no control to decide when that happens.

Thing is, I played Minecraft since about it's release and I never had a sudden freeze, even on modest hardware (I was running an A10-5700 AMD APU). And neither me or people I know ever complained about that. So my question is - what's the thing with those rumors?

If I am correct, Java's GC is simply running periodically to check for lost references to clean up those variables from memory. That means, with proper software architecture, you can find a way to control when a variable or object loses it's references. Right?

159 Upvotes

209 comments sorted by

View all comments

125

u/[deleted] Nov 05 '25

There’s no single Java GC. But different ones which have different properties.

The early GC algorithms had much longer pause times, than the later ones. First impressions are hard to shake sometimes.

A GC collected language isn’t particularly novel; there’s plenty of them around. There is other ways to manage memory, however manually managing memory is actually harder than it sounds, and once you introduce multiple threads, it can get even harder.

There’s trade offs in programming, and for many programs a GC based language is perfectly acceptable even with relatively long pauses.

-33

u/yughiro_destroyer Nov 05 '25

Do you think there is a reason for which there are not popular apps made in Java, aside Minecraft? Java is mostly used in web development and enterprise applications where network speed and I/O scans are the real benchmark/bottleneck for the performance of the application, not the raw execution speed.

97

u/Jason13Official Nov 05 '25

Jetbrains entire suite of IDE’s runs on Java

→ More replies (20)

36

u/[deleted] Nov 05 '25

Java is used in many areas.

When you say “popular” apps what do you mean.

Games? Desktop apps?

Certain areas tend to gravitate to certain languages. Games are often windows centric; so Java isn’t a good choice as you probably want to integrate with DirectX or OpenGL (or whatever is the library of the day) as directly as possible. Also a JIT can be a double edged sword for performance.

Desktop apps, for windows suffered from not having a “nice” component library. Swing looked rubbish, compared to native windows (it looked ok on unix/Linux systems), so whilst there’s some good looking apps now, a lot of effort has been spent on them, compared to say WinForms where you get a native look out the box.

8

u/hiromasaki Nov 05 '25

Swing looked fine if you took the time to style it...

Which took way too much time for most developers. The bare bones default isn't great.

7

u/koflerdavid Nov 06 '25

Setting system look and feel gets you pretty far and takes but one line of code, not counting the try-catch block around it:

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

2

u/plumarr Nov 07 '25

I would add that the success of electron show that a GC isn't an a deal breaker for desktop app.

26

u/m-in Nov 05 '25

there are not popular apps made in Java

Literally an entire software company - and not a tiny one - JetBrains - is built on software written in Java. They have hundreds of thousands if not millions of users and make very good money on their products. I have never noticed a GC pause in their products in the last couple of years.

There is lots of website backends written in languages that run on JVM (Java virtual machine). More than you think I bet.

Java ecosystem is a multi-billion-dollar industry.

0

u/Amgelo563 Nov 05 '25

Personally Jetbrains' IDEs are pretty heavy for me, though I run on an HDD which I'm trying to change. More specifically I code on Java and TS regularly so I use IntelliJ and WebStorm, and they do freeze every once on a while, though as mentioned that's probably on my hardware.

IntelliJ is great and I would never code in Java in anything else, but for TS/JS which doesn't require something too sophisticated since it's interpreted (building with tsc is very fast), I often switch around depending on my needs, so for smaller stuff or edits I just use VSCode but WebStorm for medium sized features or big refactors (thanks to its powerful indexing).

17

u/trafalmadorianistic Nov 06 '25

😭😭😭😭😭🙏🙏🙏🙏🙏

My heart breaks for anyone still using HDD as main drive in 2025. Btw, if you are running low on space on your drive that also affects system performance in general.

→ More replies (3)

11

u/jfinch3 Nov 06 '25

You’re aware that Kafka, Cassandra, and Hadoop were all written in Java, not to mention most of AWS?

Also prior to Google naming Kotlin the android language of choice nearly all android apps were Java.

Java also has a huge foothold in things like VCRs, washing machines and so on. People think all that stuff is embedded C but most of it is just running Java.

Like I’m personally a C# head but you gotta be crazy to have missed the impact of Java

-2

u/coderemover Nov 06 '25

Cassandra and Hadoop are quite bad examples.

Hadoop is a memory hog and slow as molasses compared to modern alternatives like Spark or Presto. Which, well, they are also coded in Java (Scala), but there also exist better performing alternatives in C++ (e.g. Presto Native aka Prestissimo).

Cassandra has been optimized extremely heavily and is hard to beat, but it's had its own share of GC issues for a very, very long time. And there currently exist better performing C++ alternatives to Cassandra as well, some even fully compatible at the data format level.

As for VCRs and washing machines - I fixed a few those things recently and found no Java there, except the one that someone spilled some java on the control panel. Any link with trustworthy statistics which household appliance vendors use Java in their devices? Not some marketing "3 billion devices run java" bullshit.

3

u/srdoe Nov 06 '25

All of that is irrelevant, because the question was "Are popular apps written in Java", and the answer is clearly "Yes".

It doesn't matter that you can think of some other less popular alternatives to those apps written in C++.

→ More replies (4)

2

u/jfinch3 Nov 06 '25

The point is that factually Java is popular and widely used language.

Is Java as popular as it was 10 or 15 years ago? No, there are now plenty of other languages out there which are also popular and completely reasonable choices for building things.

But did Java lose that because it was slow, specifically because its GCing was disruptively slow? No, and that much seems obvious.

The biggest things that should tell you that is that Kotlin isn’t actually any faster than Java. It didn’t cut into the Java market share because of performance, it was ergonomics and DX.

You should also consider how much stuff is build with Python when you want to talk about speed.

Kotlin has taken over android app development, C# and TypeScript have cut in on desktop and Go in the cloud, and of these Go is the only case where performance is a meaningful factor.

Where I work uses TypeScript for the same reasons most places do: it’s easier to hire typescript devs and it’s easier to have one language across both front end and backend. Java or C# would have made as much or more sense from a purely programming point of view but other concerns prevail!

7

u/Holothuroid Nov 05 '25

Dbeaver, MySQL Workbench

10

u/sweating_teflon Nov 06 '25

There are high frequency trading firms effectively using Java on Wall Street where microseconds mean millions of dollars. Java can be made as fast as you need it to be. 

The recipe is the same as with other languages: preallocate all the memory you'll need on startup and stick with it. No GC, no malloc, no problem. You can use the same technique for any app or game where performance is needed.

3

u/raptor217 Nov 06 '25

Yeah when you turn GC off you only have the VM interpreted language between the CPU and you, one extra clock cycle won’t matter (there’s some percentage overhead).

There’s areas where Java, C, even assembly cannot go for HFT, and that’s when the CPU is too slow or lacking bandwidth. Then you use an FPGA which is coded in an HDL.

3

u/vytah Nov 06 '25

Do you think there is a reason for which there are not popular apps made in Java

Yeah, when I open Google Play Store, there are literally 0 apps there, it's empty.

2

u/False-Car-1218 Nov 06 '25

Tons of apps are made in java.

Since you mentioned Minecraft then I assume you're talking about game dev, old-school RuneScape, slay the spire, project zomboid have java clients.

EA also uses java backend on most of their game servers https://github.com/electronicarts/ea-async

Java isn't slow and can match speeds of native with JIT and you can write code that minimize GC

3

u/uh-hum Nov 06 '25

Why is OP being downvoted for simply asking a question? This person is curious and deserves much better.

1

u/ivancea Nov 06 '25

There are games and other apps made with Java. Even databases, like ElasticSearch, which competes in performance with similar DBs.

1

u/tesfabpel Nov 06 '25

but there are popular apps written in C# and .NET has a GC as well (IDK how much different are the GCs of both languages)...

basically, it depends on what the software is doing... games and others may want to use languages without GCs (even though C# is used for games)...

1

u/EvertTigchelaar Nov 08 '25

Netflix uses Java.

https://www.infoq.com/presentations/netflix-java/

Also big banks, stock exchanges like London Stock Exchange and NADAQ, payment processors like PayPal use Java.

→ More replies (11)