• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Memory management

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi to All..I do have a small trecky question..
Suppose u have a class(file1) which contains only methods..say 5 methods with blank implementations of all these methods..take an example of such method--
void method1(){ }
void method2(){ } and so on.....compile this file --(say file1.java)

And on the other hand....
u have a class(file2) which contains only methods..say 10 methods with blank implementations of all these methods.
void method6(){ }
void method7(){ }...so on...compile it (say file2.java)

Now My point is that.....
So if u create objects of file1 and file2, can u tell me how much memory they would going to be allocated...???How this situation is being handled away???

Thnx in advance .....for ur most valuable suggestions...
 
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
Methods contribute absolutely nothing to the size of individual objects. An instance of a class with a thousand methods and no member variables is exactly the same size as an instance of a class with five methods and no member variables. The JVM keeps just a single copy of the code for a class, and all the instances "share" that copy.

Does that answer your question?
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Prashant,

You can also read book "Inside JVM" and some sample free chapters on the Artima.com site.

Here is the link where you will find the memory allocation in JVM.
http://www.artima.com/insidejvm/ed2/jvm2.html

Here as you will see, there is a "method area" where all the methods are stores for classes regardless of how many objects are there for any class which is what Ernest was pointing to.

More about the book here,
http://www.artima.com/insidejvm/blurb.html

Regards,
Maulin
 
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If things are going out of control, you can use a profiler to look for possible memory mistakes in your classes.
reply
    Bookmark Topic Watch Topic
  • New Topic