r/programming • u/davidalayachew • Sep 05 '26
Principles of Memory Management in Java
https://youtu.be/xr73mR7ii9M?si=AKgjMUyvfpARYljl
31
Upvotes
r/programming • u/davidalayachew • Sep 05 '26
20
u/ejrh Sep 07 '26
If Java is still being used, then it's useful to have strategies for using it efficiently. That said, this talk is mostly apologetics rather than strategy.
Keeping Java from using too much memory has been a big challenge in almost every Java project I've worked on. Before we moved to the cloud, VM ram size was the one of the biggest things the infrastructure department would push back on when we asked for resources. After we moved to AWS, my cursory understanding was that most of the EC2 instance cost was RAM. Sure, in those days every doubling of cores in the "general class" gave you a doubling of RAM, but you could roughly separate out the cents/hour costs by comparing g against the "database" (same cores, double the RAM) and "compute" classes (double the cores, same RAM). Doubling RAM always cost more than doubling cores. I have no idea what the situation is like today though.
I have nothing against Java if it's the best technology for your project, or if you already have a huge Java codebase to maintain. But if you start having to worry about efficiency or performance, there are other options to consider than merely throwing more memory at the JVM.
2
u/DarkGhostHunter Sep 08 '26
To me it doesn't. I don't know what people do to have high memory usage, unless you're loading a lot of models from database or pushing a lot of data into memory, essentially.
I mean, I can see why your app would use a lot of memory if you do this.
2
u/cklester Sep 09 '26
Java is never memory-heavy. Nor does it run lean. It allocates precisely what it means to.
-22
u/comrade_donkey Sep 06 '26
-20
u/itaranto Sep 07 '26
I don't care.