Each JVM has a runtime stack. Each frame of the method contains
A reference to the Java class containing that method. An operand stack for holding temporary values. A "local variables" array for holding function arguments and temporary results.
This array of local variables exists so that when the function is first called, the arguments to this function can be stored somewhere. An array of local variables does not actually store all local variables declared in the Java source code; rather, it is rather a temporary buffer for storing references to Java objects declared elsewhere in the heap, or for storing values ββreferenced many times so that placing them in the execution stack would be slow or inefficient.
In short, you are correct that locals and globals are stored on the heap. The "local variables" array in Java streams does not match these local networks, but rather scratches the space used by the stream when interpreting the bytecode for this method.
source share