Results 1 to 2 of 2
- 10-01-2009, 09:04 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 8
- Rep Power
- 0
- 10-04-2009, 01:48 AM #2
The following example shows how much memory that JVM has allocated for your application:
The following example shows how to discover how much memory is free within the application:Java Code:Runtime runtime = Runtime.getRuntime(); System.out.println("allocated memory: " + runtime.totalMemory() / 1024);
The freeMemory() method will return the amount of free memory from the allocated memory. Since this value does not include any memory that hasn't yet been allocated by the JVM, you will need to get a complete picture of the free memory that your application would be able to use. To do this, you need to include the amount of memory that hasn't yet bee allocated by the JVM, but could be allocated if necessary.Java Code:Runtime runtime = Runtime.getRuntime(); System.out.println("free memory: " + runtime.freeMemory() / 1024);
Java Code:Runtime runtime = Runtime.getRuntime(); long maxMemory = runtime.maxMemory(); long allocatedMemory = runtime.totalMemory(); long freeMemory = runtime.freeMemory(); System.out.println("free memory: " + freeMemory / 1024); System.out.println("allocated memory: " + allocatedMemory / 1024); System.out.println("max memory: " + maxMemory /1024); System.out.println("total free memory: " + (freeMemory + (maxMemory - allocatedMemory)) / 1024);
Similar Threads
-
Need help in knowing how to clear buffer.
By tedstevens in forum New To JavaReplies: 1Last Post: 08-20-2009, 05:02 AM -
Knowing which IP address is active
By sukatoa in forum NetworkingReplies: 2Last Post: 05-05-2009, 04:01 PM -
problem with HTTP Status 404
By orkun in forum JavaServer Faces (JSF)Replies: 1Last Post: 02-05-2009, 09:28 PM -
Problem with jre-6u10-windows-i586-p-s.exe install - HELP
By g8rntx in forum Java AppletsReplies: 1Last Post: 11-21-2008, 02:13 AM -
SWT Status Bar Demo
By Java Tip in forum SWTReplies: 0Last Post: 07-25-2008, 02:20 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks