简体   繁体   中英

How to drain the java thread stack memory area?

In C, I can drain the stack memory area with following small program(the limit of stack size in my Mac is 8MB)

int main(int argc, const char **argv) {
  int a[1024*1024*2];
  long size = sizeof(a);
  return 0;
}

Since array is java is also an object, its element are stored in heap. According to Oracle's doc , the default thread stack size is 512KB in Mac. Is there any program can drain the stack size ?

Stack values only exist within the scope of the function they are created in. Once it returns, they are discarded.

Now Java only stores primitives on the stack.

So they only way to drain the stack would be to create primitives. In this is a recursive method then I guess you could observe some drain before a StackOverflowError.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM