Relationship Between JVM Memory & Heap Size
The Java Virtual Machine represents the basis of the Java programming language. The software acts as an implementation buffer between Java code and the underlying computer system. This allows Java code to run on any system as-is, increasing portability. Since the JVM exists as an environment in which to run the code, it contains its own memory configuration, including shallow memory and heap space. The heap space makes up a significant portion of the JVM memory, containing critical application run-time data.
-
Objects and Memory
-
Java represents a purely object-oriented programming language, meaning that Java contains the benefits of object-oriented programming, including inheritance and polymorphism. To include these benefits, the JVM must have a space to store instantiated objects. These objects do not exist in the immediate memory of a an executing thread of Java code. Rather, Java code declares "references" to objects that store a location in deep, long-term memory.
The Heap and the Stack
-
The heap and the stack represent the difference between long- and shorter-term memory in an executing program, regardless of object-oriented language. The stack refers to the immediate variables and method calls inside an executing program. This includes scalar variables, such as integers and bytes, as well as functions called. The heap, on the other hand, represents the location where objects created are stored by the program. Objects are allocated dynamically into the heap and stay there until no longer required by the program.
-
JVM Memory
-
Designers developed the JVM's memory system to mimic the object-oriented system of other languages such as C++. Each executing thread of Java code in the JVM has its own stack, representing its local scalar variables and function calls. Furthermore, the JVM has its own heap space. When a program creates a reference to an object, that object draws memory from the collective heap space.
The Heap in JVM Memory
-
The heap space is only part of the total JVM memory, along with stack space and other memory allocations for crucial functions and JVM code. However, the heap space represents a crucial part of the JVM in that it is the vehicle by which objects are created. Also, the JVM has a built-in garbage collecting program to delete unused objects from the heap. In older object-oriented languages, objects had to be deleted manually, or risked using up the heap space in what was called a "memory leak." JVM's garbage collector, however, monitors the heap and deletes old objects.
-