My Java application is for system with small memory. How to get the system's fre
JavaFAQ Home » General Java
Question: I am writing a Java application for
system with small memory.
To make it reliable I would like to monitor memory size in
my program and try to decrease program activity to enable Garbage Collector do
its job before all memory will be consumed. When enough memory will be available
program must continue the job.
How can I info about free memory in my Java application?
Answer: Your idea to design
long time running program for an extreme environment is excellent!
Runtime.totalMemory() - you get the total amount of memory in the Java
virtual machine. This value varies all the time, depending on the host
environment. Note that the amount of memory required to hold an object of any
given type may be implementation-dependent...
Runtime.freeMemory() - you get info about free memory in the
Java Virtual Machine. Calling the
gc method may result in
increasing the value returned by
Printer Friendly Page
Send to a Friend
Search here again if you need more info!