Java Memory Used getMemoryInUse()

Here you can find the source of getMemoryInUse()

Description

Returns the number of megabytes (MB) of memory in use.

License

Open Source License

Declaration

public static int getMemoryInUse() 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   w w  w  . j  ava  2  s .c  o  m
     * Returns the number of megabytes (MB) of memory in use.
     */
    public static int getMemoryInUse() {
        Runtime runtime = Runtime.getRuntime();
        long mb = 1024 * 1024;
        long total = runtime.totalMemory();
        long free = runtime.freeMemory();
        return (int) ((total - free) / mb);
    }
}

Related

  1. calcUsedMemorySize()
  2. disposeUnusedMemory()
  3. getAvailableUnusedMemory()
  4. getMemoryUse()
  5. getMemoryUsed()
  6. getMemoryUsed()
  7. getMemoryUsed()