


In addition, variables on the stack have a certain visibility, also called scope. Stack memory is responsible for holding references to heap objects and for storing value types (also known in Java as primitive types), which hold the value itself rather than a reference to an object from the heap. The heap is a huge amount of memory compared to the stack. Generally, memory is divided into two big parts: the stack and the heap. Please keep in mind that the size of memory types in this picture are not proportional to the memory size in reality. To start with, let’s have a look at how the memory is generally organized in Java: On the other hand, when you find yourself in a bad situation, you will be able to quickly find the memory leak. So knowing how memory actually works in Java is important, as it gives you the advantage of writing high-performance and optimized applications that will never ever crash with an OutOfMemoryError. By not knowing how the garbage collector and Java memory is designed, you could have objects that are not eligible for garbage collecting, even if you are no longer using them. However, even if this process is automatic in Java, it does not guarantee anything. Therefore, you as a Java programmer do not need to bother yourself with problems like destroying objects, as they are not used anymore.
#Memory master rules free#
You might think that if you are programming in Java, what do you need to know about how memory works? Java has automatic memory management, a nice and quiet garbage collector that works in the background to clean up the unused objects and free up some memory.
