I am new to java and still learning. I got my head around inner and anonymous classes. Now I have a technical question about how java looks like in memory, when allocating objects, defining classes, etc.
Like what does memory look like when I have a field that is an object that is defined in an outside class vs an inner class. Do static classes look different than non static?
I just need a visual reference.
Thanks Guys
In Java, all objects are dynamically allocated on Heap. This is different from C++ where objects can be allocated memory either on Stack or on Heap. In C++, when we allocate the object using new(), the object is allocated on Heap, otherwise on Stack if not global or static.
Heap space is used for the dynamic memory allocation of Java objects and JRE classes at runtime. New objects are always created in heap space, and the references to these objects are stored in stack memory.
A memory layout can be used to describe the contents of a memory segment in a language neutral fashion.
Memory Management in Java refers to allocating and deallocating memory to java objects which reside in areas called Stack and Heap. Java has an automatic memory deallocation system known as Garbage Collector.
Helpful link
http://www.artima.com/insidejvm/ed2/jvm6.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With