how much memory is allocated to our main function and normal function in our jvm stack
Memory allocation
Hi Aman
The JVM stack comes with a default storage size of 1mb which can be increased to 4mb. Main function is just like other functions except that it will be the first function to be called in the execution trace.Hence main is the first function that is stored into the stack.
However the amount of memory allocated to any function(main included) depends on the size of the function, A bigger function will take more memory compared to a smaller function.
Also each instance call of a function will store it in the stack. This is how we get the famous StackOverflow error if our recursion runs into an infinite loop as we calling the same function infinite times, thus exceeding the 1mb limit…
ok , function exceeded after 1 mb but you mentioned in starting line stack size can increase upto 4 mb ??
hey ! you haven’t answered my question
Hi Aman
Looks like my reply was not registered by the server hence not showing up on your side.
What I said was that JVM stack size can be increased to 4 mb through the use of thread execution, which is done mostly through Tomcat config tool.
However you are not required to go into the specifics of these as it is advanced java applications and not required for coding aspect.
In coding the memory allocated to stack will most of the time be given in the question, else assume it to be 1 mb.