Forums Register Login

how primitives and objects are laid in memory?

+Pie Number of slices to send: Send
Hi Folks,
I want to know how java objects and primitives objects are laid out in memory. How static variables and objects are stored. For ex
int a = 12;
how memory allocation happens for variable a.
Thanks in advance.
Fred
+Pie Number of slices to send: Send
"Fred",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp.
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please edit your profile and select a new name which meets the requirements.
Please be sure to change your display name soon. Accounts with invalid names get deleted.
Thanks.
Dave
+Pie Number of slices to send: Send
Objects are stored on the heap. Static variables are stored with the Classfile. Variable references are stored in the stack related to the Frame. There is a frame for each method invoked. So local variables find themselves on the stack for the method that they are local to.
The example that you gave shows the integer as a constant value. That value would be stored in the Constant Pool, with all the other constants and literals and Strings.
You may enjoy reading the Java Virtual Machine Specifications for details on how such things work. .
Warning! Way too comfortable! Do not sit! Try reading this tiny ad instead:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 638 times.
Similar Threads
garbage collection
Stack & Heap
Constructor Confusion
Why do Collections(save Arrays) allow only Objects?
Object in Memory
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:10:21.