r/java • • Jan 06 '26

One step closer to Value Classes!

https://mail.openjdk.org/pipermail/porters-dev/2026-January/000844.html
183 Upvotes

118 comments sorted by

View all comments

Show parent comment

3

u/chambolle Jan 07 '26

Java uses a little extra memory, but that's not where the memory consumption really comes from. This extra memory adds something like a 64-bit integer for an object, so it would take billions of objects for it to be noticeable.

The real reason for memory consumption is that many Java programs and libraries (including system ones) use temporary internal objects without any problems, since they assume that the garbage collector will handle all memory management. The proof of this is that it is never mentioned whether temporary objects are created when a function is called. As a result, many programs do not work with Epsilon GC, whereas if memory were better managed, they could.

This is one of the drawbacks of languages that use garbage collectors: users no longer care about the lifetime of objects, which leads to excessive memory consumption.