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.
The moose likes Beginning Java and the fly likes memory map of objects Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "memory map of objects" Watch "memory map of objects" New topic
Author

memory map of objects

Ravi Gupta
Ranch Hand

Joined: Jul 15, 2006
Posts: 38
We all know that objects have their own copy of instance variables. But what about methods ? Do the methods that are non-static, occupy memory for every object that is created, i.e. does Java make a distinction between memory maps of instance variables and instance methods or not ? The question may seem too naive but i could not find this fact explicitly cited in any of the books on Java that i have and i happen to have a lot of them.


help your PC help you best
http://simplepccare.spaces.live.com
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32708
    
    4
Don't know.
You need to try going through the Java website. Start here with the JVM documentation.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24057
    
  13

No, each method does not contribute to the size of each object; methods, and information about methods, is stored just once.

There are many ways to implement this, and the details of the implementation change from time to time, but all are variations on the classic vtbl approach. Every object does have a reference to a class-wide data structure. Part of that data structure is a list of methods and reference to the code for each method. To invoke a method on an object, the VM follows the chain of references from the object, to the class, to the code for the method.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: memory map of objects
 
Similar Threads
What is stored on Stack and Heap
where do static variables live ?
Memory Allocation
regarding memory and doubt abt static
Stack memory and Heap memory in java