File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How will I know how much memory can be used by my java application?

 
Minal Silimkar-Urankar
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After designing of java application, I want to know, how much memory can be used by my java application? How will I know it?
 
Andre Brito
Ranch Hand
Posts: 95
Java Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait. How much memory your program WILL use or how much memory you can 'allocate' for it?

If it's the second, you can configurate that through -Xms and -Xmx.
 
Minal Silimkar-Urankar
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I execute my application, how much memory will get allocated by applications?
 
Lakshman Erukulla
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You can create an instance for the Runtime class and use the totalmemory() method in it to know the total amount of memory in the Java virtual machine as well as you can use the freeMemory() method which returns the amount of free memory in the Java Virtual Machine. If there are any queries you can contact me here. Thank you.
 
Lakshman Erukulla
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Runtime class is available in java.lang package
 
Minal Silimkar-Urankar
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Functions from class java.lang.Runtime
freeMemory() returns the amount of free memory in the Java Virtual Machine.
totalmemory() returns the total amount of memory in the Java virtual machine.
Lets take an example:

In above code class employee have two variables declared of type int and float. If I create object of class Employee one object will occupy total 8 bytes of memory. Similarly, if I designed whole application, can I directly calculate how much memory my whole application will occupy.
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
minal silimkar wrote:If I create object of class Employee one object will occupy total 8 bytes of memory.

Plus overhead. Java classes are not like C structs which does have a known size that is simply the sizes of all its members added up.
 
Minal Silimkar-Urankar
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That means do I have to manually calculate total memory may be accupied by my application? There is no direct way to find out using java?
 
Lakshman E
Greenhorn
Posts: 4
Firefox Browser Ubuntu Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the delay minal silimkar . I think your problem has been resolved.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic