Rameshwar.S.Soni
Rameshwar.S.Soni

Reputation: 608

Java Stack and Heap

Why is
Stack : Stored in Computer RAM like heap and
Heap : Stored in Computer RAM like stack ?

according to the nice answer by "Brain R Bondy" here

I am using Java language. Also what if i have too less RAM.

Upvotes: 2

Views: 337

Answers (3)

Cephalopod
Cephalopod

Reputation: 15145

Everything has to be stored in main memory (RAM) at some point, otherwise the CPU cannot work with it.

If you're running out of RAM, the operating system will outsource some of your application's memory to disk. This will make your program slow, but not break it. Because of this, the amount of memory your program can use does not depend on the amount of RAM that is physically available.

If you get stack overflow errors, you probably have an infinite recursion bug in your program.

If you get heap space/out of memory errors, see this question: What does Java option -Xmx stand for?

Upvotes: 2

LuGo
LuGo

Reputation: 5045

This means only, that they are both kept in the RAM.

Upvotes: 1

Lakatos Gyula
Lakatos Gyula

Reputation: 4160

To let the processor access them as fast as possible, because they are used a lot.

Upvotes: 1

Related Questions