• 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
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

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: 24204
44
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.
 
You would be much easier to understand if you took that bucket off of your head. And that goes for the tiny ad too!
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic