Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > stack and heap question

Reply
Thread Tools

stack and heap question

 
 
joe
Guest
Posts: n/a
 
      08-04-2004
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 ?

 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      08-04-2004
joe wrote:
> 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
 
Reply With Quote
 
 
 
 
Phillip Mills
Guest
Posts: n/a
 
      08-04-2004
In article <cequjh$(E-Mail Removed)>,
"joe" <(E-Mail Removed)> wrote:

> 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.

--
Phillip Mills
Multi-platform software development
(416) 224-0714
 
Reply With Quote
 
Michael Borgwardt
Guest
Posts: n/a
 
      08-05-2004
joe wrote:
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How much heap can I reserve for JVM? Error when allocation very much heap Raymond Schanks Java 0 04-11-2010 04:25 PM
C/C++ compilers have one stack for local variables and return addresses and then another stack for array allocations on the stack. Casey Hawthorne C Programming 3 11-01-2009 08:23 PM
stl heap question: restoring heap validinty after changing 1 element viki C++ 6 06-28-2008 10:12 AM
Heap dump file size vs heap size Michal Slocinski Java 1 03-25-2008 12:54 PM
C++ Objects, Stack or Heap? [Noob question] Olumide C++ 14 09-21-2004 12:32 PM



Advertisments