stack and heap question

J

joe

There is a tomcat web application that is crashing. I think.. I not
sure what is going really , relable information is hard to come by from
these people. They think it is a memory problem, they are running out
of it.

In my discusions with them this is what I was told.

"When you allocate primitives they aren't allocated on the heap but on
the stack." I am pretty this part is right, I took a quick look at
Rodney's site to confirm this.

Now what they are saying is that it is not the heap consuming all the
memory but the stack.

I having a hard time believing this. Is this possible ?, Wouldn't
garbage collection take of this problem ?
 
C

Chris Smith

joe said:
In my discusions with them this is what I was told.

"When you allocate primitives they aren't allocated on the heap but on
the stack." I am pretty this part is right, I took a quick look at
Rodney's site to confirm this.

That's not true. Primitives are variables, and they act like all other
variables in this regard. Where variables are allocated depends on what
kind of variable they are. If it's a local variable, it's allocated on
the stack. If it's an instance field, it's allocated on the heap. If
it's a static field, it's allocated into a special static data area that
is generally on neither the stack nor the heap.
Now what they are saying is that it is not the heap consuming all the
memory but the stack.

I having a hard time believing this. Is this possible ?, Wouldn't
garbage collection take of this problem ?

No, the garbage collector does not take care of managing space on the
stack. That's because space on the stack is reclaimed the instant it
goes out of scope, so there is no need for a garbage collector.

If you are running out of stack space (called a "stack overflow"), it's
generally because you are using deep recursion. That's often due to a
bug in code that causes it to miss the boundary condition on a recursive
algorithm, but it could also be because you just have a very large
problem. One possible solution is to convert to a non-recursive
algorithm that uses an explicit stack data structure (as opposed to
using "the" stack, which is what you use by calling methods and
declaring local variables). That moves data from the stack (which is
generally small) to the heap (which is much larger).

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
P

Phillip Mills

joe said:
Is this possible ?, Wouldn't
garbage collection take of this problem ?

It's a bit unusual, but possible. If you have a very deep call
chain...perhaps with lots of local variables. Infinite recursion is the
ultimate example.

I can't imagine garbage collection being any help with stack frames.
 
M

Michael Borgwardt

joe said:
Now what they are saying is that it is not the heap consuming all the
memory but the stack.

I having a hard time believing this. Is this possible ?

Yes and no. You sure can run out of stack memory, and you can tell that
case apart from running out of heap memory by the type of Exception
thrown (StackOverFlowError vs. OutOfMemoryError).

But the stack in Java cannot "consume all the memory" unless you create an
excessive number of threads, because you have a relatively small fixed-size
stack memory per thread.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Heap and Stack 5
pImpl idiom: Heap vs Stack 14
heap vs stack 3
stack and heap 9
Stack is slow than heap? 23
An idea for heap allocation at near stack allocation speed 14
Detecting stack or heap instances 2
Stack and Heap 16

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top