Java Memory Usage describeMemoryUsage()

Here you can find the source of describeMemoryUsage()

Description

Returns a string that describes the JVM's memory conditions in this format: 36M used, 29M free, 533M max .

License

Apache License

Declaration

public static String describeMemoryUsage() 

Method Source Code

//package com.java2s;
/**/*from   www. j  a va  2s. com*/
 * Copyright 2012 55 Minutes (http://www.55minutes.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Returns a string that describes the JVM's memory conditions in this
     * format: {@code 36M used, 29M free, 533M max}.
     */
    public static String describeMemoryUsage() {
        Runtime runtime = Runtime.getRuntime();
        long free = runtime.freeMemory();

        return String.format("%sM used, %sM free, %sM max", (runtime.totalMemory() - free) / 1000000,
                free / 1000000, runtime.maxMemory() / 1000000);
    }
}

Related

  1. estimateMemoryUsage(String s)
  2. getMemberName(int number)
  3. getMemInfo()
  4. getMemoryFootprint()