• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

memory map of objects

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 80763
488
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know.
You need to try going through the Java website. Start here with the JVM documentation.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic