Java Memory dumpMemoryInfo(String msg)

Here you can find the source of dumpMemoryInfo(String msg)

Description

Dumps out memory information

License

Open Source License

Parameter

Parameter Description
msg addditional text for the dump

Declaration


public static void dumpMemoryInfo(String msg) 

Method Source Code

//package com.java2s;
/*/*from   w w w.  j a va2s . c o m*/
 * Copyright 1999-2002 Carnegie Mellon University.  
 * Portions Copyright 2002 Sun Microsystems, Inc.  
 * Portions Copyright 2002 Mitsubishi Electric Research Laboratories.
 * All Rights Reserved.  Use is subject to license terms.
 * 
 * See the file "license.terms" for information on usage and
 * redistribution of this file, and for a DISCLAIMER OF ALL 
 * WARRANTIES.
 *
 */

public class Main {
    static long maxUsed;

    /**
     * Dumps  out memory information
     *
     * @param msg addditional text for the dump
     */

    public static void dumpMemoryInfo(String msg) {
        Runtime rt = Runtime.getRuntime();
        long free = rt.freeMemory();
        rt.gc();
        long reclaimedMemory = (rt.freeMemory() - free) / (1024 * 1024);
        long freeMemory = rt.freeMemory() / (1024 * 1024);
        long totalMemory = rt.totalMemory() / (1024 * 1024);
        long usedMemory = rt.totalMemory() - rt.freeMemory();

        if (usedMemory > maxUsed) {
            maxUsed = usedMemory;
        }

        System.out.println("Memory (mb) " + " total: " + totalMemory
                + " reclaimed: " + reclaimedMemory + " free: " + freeMemory
                + " Max Used: " + (maxUsed / (1024 * 1024)) + " -- " + msg);
    }
}

Related

  1. checkMinMemory(long min)
  2. compactMemory()
  3. correctMemoryValue(int memory)
  4. displayMemory(String label, long bytes)
  5. dumpMemory()
  6. fillMemory()
  7. isDefaultMemoryCardDrive(String aRoot)
  8. isInMemoryDatabase(final String databasePath)
  9. isMemoryAccess(final String value)