This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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
"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
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
posted
0
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. .
"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: how primitives and objects are laid in memory?