Here you can find the source of dumpMemoryInfo(String msg)
Parameter | Description |
---|---|
msg | addditional text for the dump |
public static void dumpMemoryInfo(String msg)
//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); } }