Skip to main content

How does Java decide between Heap and Stack?

2 replies [Last post]
Joined: 2009-09-25

I was coding in C a while ago and got a bug I couldn't figure out for a long time.
I've just started in Java & want to avoid a similar error.

It had something like

function X() {
int bigArr[10,000]

.... more code .....

I finally showed it to someone else, and he said "Oh, put that bigArr on the heap. Its on
the stack now and is blowing up the rest of the code on the stack.

I'm now planning to use a data structure that could get quite big. Could I run into the
same type of bug as the old "C" problem? Is there any general tips to avoid "gotchas"
when declaring varibles?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-09-13
Joined: 2009-09-25

Thanks for the reply!

I had searched on both heap & stack, but somehow missed that other thread.

Sorry about the duplicate question, but thanks again for the answer.