Java stack create new frame for every method call, But does this frame takes memory on the stack?
To clarify on my question :
public void oneWay()
{
System.out.println("start");
get1();
}
private void get1()
{
System.out.println("get1");
get2();
}
private void get2()
{
System.out.println("get2");
}
Output of this is same as :
public void anotherWay()
{
System.out.println("start");
System.out.println("get1");
System.out.println("get2");
}
But does second snippet takes more memory on stack or equal? In short, does stack frame take memory?
EDIT : How much memory does a stack frame take? Is there any specification by Sun, now Oracle?
Count the number of complete strings, multiply by 8 (since "STACK---" is 8 bytes long), and you have the number of bytes of remaining stack space.
The stack frame is 32-byte-aligned.
There is no standard minimum size for a stack frame. The maximum size of a stack frame depends on the platform and implementation. A common implementation is to have the stack to expand towards the heap and the heap expands towards the stack.
An individual stack frame has space for actual parameters, temporary locations, local variables and calling subroutine information.
Yes, naturally. That's why you get a stack overflow if you nest too deep. You can use the -Xss
command line switch to modify the stack size, if you find that you need to have a bigger (or smaller) stack for your threads.
The specification seems to allow a lot of freedom for the implementation, so all in all, you can't really rely on stack frame size.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With