aspose file tools*
The moose likes Performance and the fly likes Want to know how and where to use MemoryUsage methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Want to know how and where to use MemoryUsage methods" Watch "Want to know how and where to use MemoryUsage methods" New topic
Author

Want to know how and where to use MemoryUsage methods

Pooja Patole
Ranch Hand

Joined: Mar 13, 2012
Posts: 35
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

Joined: Jul 20, 2010
Posts: 10
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

Joined: Mar 17, 2011
Posts: 7676
    
  19

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


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Pooja Patole
Ranch Hand

Joined: Mar 13, 2012
Posts: 35
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
Bartender

Joined: Jan 17, 2008
Posts: 2337
    
  28

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

Joined: Aug 22, 2010
Posts: 3610
    
  60

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
Bartender

Joined: Jan 17, 2008
Posts: 2337
    
  28

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.
 
Don't get me started about those stupid light bulbs.
 
subject: Want to know how and where to use MemoryUsage methods