Jump to content
  • Advertisement
Sign in to follow this  
Concentrate

Java : Garbage Collection

This topic is 3129 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Why does java not have memory on stack? They try to be as efficient as allocation in stack by their allocation of heap for objects, but why not just have allocation on stack?

Share this post


Link to post
Share on other sites
Advertisement
Cause they wanted Java to be simpler than C and C++. Garbage collection allows faster development, as there's less complication for the programmer. It's a business decision they took when developing the language. I guess they weighed the cost and benefits, and decided to go with it. Java and the JRE works pretty well, and has gotten quicker over the years.

Share this post


Link to post
Share on other sites
Early implementations of Java didn't have fast heap allocation. They didn't design the language to have efficient allocation, they designed it to be safe. Stack allocation brings issues relating to invalid references. C#, with the benefit of hindsight, allows for value and reference types to get around this.

This article says that modern JVMs perform escape analysis and can stack allocate (or even just use registers) in the case where an object does not live longer than a single function.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!