Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Memory management

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
I promise I will be the best, most loyal friend ever! All for this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic