Alex Rivera | Logout

Why do you need to specify the Java heap size?

Asked 2010-08-18T21:02:31.230
20

I have always wondered, why does Java require you set the heap size manually? I was under the impression that programs written in other languages would just allocate as much memory as needed as the program run until the OS could allocate no more.

In the Java world we need to set the heap, stack, and permgen size. While this is simple enough forgetting to increase these to "large enough" numbers is the #1 reason I have seen servers go down.

Why is it not possible to tell Java to grow the heap/stack/permgen as much as it needs over time?

Edit
Report

1 Answer

1

Because growing the heap, stack, and permgen size dynamically just would make the server go down anyway. In such a world, the server would eventually leak away all of its resources.

Also, developing automatic memory management wasn't as mature as it is today. Having virtual limits makes things easier if you pick the wrong defaults, but it can make the coding a bit less efficient on the back end.

Yes, these are guesses, but reasonable ones; especially when you consider Java's / Oak's origins of embedded set top box programming. It isn't like an embedded system is going to have swap or disk backed virtual memory, so why make the JVM act as if it were available?

answered 2010-08-18T21:14:15.547

Your Answer