This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Zero to AI - A non-technical, hype-free guide to prospering in the AI era and have Nicolò Valigi and Gianluca Mauro on-line!
See this thread for details.
Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning 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
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

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

 
Ranch Hand
Posts: 136
  • 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?
 
Ranch Hand
Posts: 95
Scala Java
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I execute my application, how much memory will get allocated by applications?
 
Greenhorn
Posts: 2
  • 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
  • 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
  • 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.
 
Sheriff
Posts: 22015
108
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • 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
  • 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?
 
Greenhorn
Posts: 4
Firefox Browser Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the delay minal silimkar . I think your problem has been resolved.
 
reply
    Bookmark Topic Watch Topic
  • New Topic