Java Memory Information getMemoryStats()

Here you can find the source of getMemoryStats()

Description

get Memory Stats

License

Apache License

Declaration

public static String getMemoryStats() 

Method Source Code

//package com.java2s;
/*/*  ww w  .jav  a2 s .  c o  m*/
 * Copyright (C) 2012 The Stanford MobiSocial Laboratory
 * 
 * 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 {
    public static String getMemoryStats() {
        Runtime r = Runtime.getRuntime();
        System.gc();
        int MB = 1024 * 1024;
        return r.freeMemory() / MB + " MB free, " + (r.totalMemory() / MB - r.freeMemory() / MB) + " MB used, "
                + r.maxMemory() / MB + " MB max, " + r.totalMemory() / MB + " MB total";
    }
}

Related

  1. getMemoryConsumedSincePreviousCall()
  2. getMemoryIncrease()
  3. getMemoryInfo()
  4. getMemoryLimit()
  5. getMemoryLimitMinSize()
  6. getMemoryStats(int mode)
  7. getMemoryStatus(boolean preRunGarbageCollector)
  8. getMemoryString()
  9. getMemoryString()