Java Memory Information getMemoryStats(int mode)

Here you can find the source of getMemoryStats(int mode)

Description

Returns the desired information about the game's memory

License

Open Source License

Parameter

Parameter Description
mode Use RuntimeHelper.XXX_MEMORY (total, used, free)

Return

The desired information

Declaration

public static int getMemoryStats(int mode) 

Method Source Code

//package com.java2s;
/*//w w w . j  a v a  2  s. c  om
 * Copyright (c) 2014 mgamelabs
 * To see our full license terms, please visit https://github.com/mgamelabs/mengine/blob/master/LICENSE.md
 * All rights reserved.
 */

public class Main {
    public static final int TOTAL_MEMORY = 0;
    public static final int USED_MEMORY = 1;
    public static final int FREE_MEMORY = 2;
    private static Runtime runtime;

    /**
     * Returns the desired information about the game's memory
     *
     * @param mode Use RuntimeHelper.XXX_MEMORY (total, used, free)
     * @return The desired information
     */
    public static int getMemoryStats(int mode) {

        switch (mode) {

        case TOTAL_MEMORY:
            return (int) (runtime.totalMemory() / 1024 / 1024);

        case USED_MEMORY:
            return (int) ((runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024);

        case FREE_MEMORY:
            return (int) (runtime.freeMemory() / 1024 / 1024);

        }

        return 0;

    }
}

Related

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