Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Want to know how and where to use MemoryUsage methods

 
Pooja Patole
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I have written a class and wanted to check how much memory it is consuming using MemoryUsage methods getInit(), getUsed(), getCommitted(). How should i use them???I know the question is sounding vague but If you could explain this to me with an example it would be great.


Thanks
Pooja
 
Frank Pavageau
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Init is the amount of memory allocated on startup (-Xms for the total heap, for example).
Used is the current usage value.
Committed is the the maximum amount currently reserved by the JVM : it has been allocated by the OS to the JVM and is available for the application, even if it's not totally used at the moment. It can be less than the maximum possible amount (-Xmx for the total heap, for example).

You could also use JConsole or JVisualVM to inspect the memory usage without writing any code.
 
Winston Gutkowski
Bartender
Pie
Posts: 10492
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pooja Patole wrote:I have written a class and wanted to check how much memory it is consuming using MemoryUsage methods getInit(), getUsed(), getCommitted(). How should i use them??? I know the question is sounding vague but If you could explain this to me with an example it would be great.

Frank has given you the basics, but it may be worth pointing out that it can really only be used for "symptomatic" purposes (ie, when you have a memory problem, and you're trying to find out what it is). If you follow good QA dictates, the chances are that you'll never need it.

I can honestly state that I have never used a profiler in the last 20 or so years I've been programming - the first 10 are another story, but I do have the excuse that there was a lot less memory around then .

Winston
 
Pooja Patole
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OKay !! But i have to use this . My Sir has given me an assignment and couldn't find any help on the internet. .
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
I can honestly state that I have never used a profiler in the last 20 or so years I've been programming - the first 10 are another story, but I do have the excuse that there was a lot less memory around then .

Winston


There is no such thing as too much memory! When you memory becomes cheaper, applications grow to use that memory :p
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jayesh A Lalwani wrote:There is no such thing as too much memory! When you memory becomes cheaper, applications grow to use that memory :p

Not just memory, every resource. That explains why nowadays MS Word 2010 begins to have difficulties with a document that has grown over about 100 pages - eerily similar to the practical limit of word 2.0 nearly twenty years ago, when all resources - CPU, memory, hdd - were at least thousand times smaller than now.
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah even the whole JDK would fit on a 1.44M floppy disk back in 95. Now just the rt.jar on my local system is 50M

Of course Java is doing a lot more now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic