All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.spun.util.Memory Maven / Gradle / Ivy

There is a newer version: 24.9.0
Show newest version
package com.spun.util;

/**
 * A Simple class looking at memory.
 * @author Llewellyn
 * @version 1.0
 **/
public class Memory
{
  private long                   freeMemory  = 0;
  private long                   totalMemory = 0;
  private long                   usedMemory  = 0;
  private java.text.NumberFormat format      = java.text.NumberFormat.getNumberInstance();
  /**
   * Dumps the current memory status [total, used, free].
   * This forces garbage collection to run first.
   **/
  public Memory()
  {
    System.gc();
    freeMemory = Runtime.getRuntime().freeMemory();
    totalMemory = Runtime.getRuntime().totalMemory();
    usedMemory = totalMemory - freeMemory;
  }
  public String getUsedMemory()
  {
    return format.format(((double) usedMemory) / 1000000);
  }
  public String getFreeMemory()
  {
    return format.format(((double) freeMemory) / 1000000);
  }
  public String getTotalMemory()
  {
    return format.format(((double) totalMemory) / 1000000);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy