Package weka.core

Class Memory

java.lang.Object
weka.core.Memory
All Implemented Interfaces:
RevisionHandler

public class Memory extends Object implements RevisionHandler
A little helper class for Memory management. The memory management can be disabled by using the setEnabled(boolean) method.
Version:
$Revision: 11271 $
Author:
FracPete (fracpete at waikato dot ac dot nz)
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
     
    static final long
     
    static final long
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    initializes the memory management without GUI support
    Memory(boolean useGUI)
    initializes the memory management
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    returns the currently used size of the JVM heap, obtains a fresh MemoryUsage object to do so.
    long
    returns the initial size of the JVM heap, obtains a fresh MemoryUsage object to do so.
    long
    returns the maximum size of the JVM heap, obtains a fresh MemoryUsage object to do so.
    Returns the revision string.
    boolean
    whether to display a dialog in case of a problem (= TRUE) or just print on stderr (= FALSE)
    boolean
    returns whether the memory management is enabled
    boolean
    checks if there's still enough memory left by checking whether there is still a 50MB margin between getUsed() and getMax().
    static void
    main(String[] args)
    prints only some statistics
    boolean
    Checks to see if memory is running low.
    void
    setEnabled(boolean value)
    sets whether the memory management is enabled
    boolean
    Prints a warning message if memoryIsLow (and if GUI is present a dialog).
    void
    prints an error message if OutOfMemory (and if GUI is present a dialog), otherwise nothing happens.
    void
    stops all the current threads, to make a restart possible
    static double
    toMegaByte(long bytes)
    returns the amount of bytes as MB

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • Memory

      public Memory()
      initializes the memory management without GUI support
    • Memory

      public Memory(boolean useGUI)
      initializes the memory management
      Parameters:
      useGUI - whether a GUI is present
  • Method Details

    • isEnabled

      public boolean isEnabled()
      returns whether the memory management is enabled
      Returns:
      true if enabled
    • setEnabled

      public void setEnabled(boolean value)
      sets whether the memory management is enabled
      Parameters:
      value - true if the management should be enabled
    • getUseGUI

      public boolean getUseGUI()
      whether to display a dialog in case of a problem (= TRUE) or just print on stderr (= FALSE)
      Returns:
      true if the GUI is used
    • getInitial

      public long getInitial()
      returns the initial size of the JVM heap, obtains a fresh MemoryUsage object to do so.
      Returns:
      the initial size in bytes
    • getCurrent

      public long getCurrent()
      returns the currently used size of the JVM heap, obtains a fresh MemoryUsage object to do so.
      Returns:
      the used size in bytes
    • getMax

      public long getMax()
      returns the maximum size of the JVM heap, obtains a fresh MemoryUsage object to do so.
      Returns:
      the maximum size in bytes
    • isOutOfMemory

      public boolean isOutOfMemory()
      checks if there's still enough memory left by checking whether there is still a 50MB margin between getUsed() and getMax(). if ENABLED is true, then false is returned always. updates the MemoryUsage variable before checking.
      Returns:
      true if out of memory (only if management enabled, otherwise always false)
    • memoryIsLow

      public boolean memoryIsLow()
      Checks to see if memory is running low. Low is defined as available memory less than 20% of max memory.
      Returns:
      true if memory is running low
    • toMegaByte

      public static double toMegaByte(long bytes)
      returns the amount of bytes as MB
      Returns:
      the MB amount
    • showOutOfMemory

      public void showOutOfMemory()
      prints an error message if OutOfMemory (and if GUI is present a dialog), otherwise nothing happens. isOutOfMemory() has to be called beforehand, since it sets all the memory parameters.
      See Also:
    • showMemoryIsLow

      public boolean showMemoryIsLow()
      Prints a warning message if memoryIsLow (and if GUI is present a dialog).
      Returns:
      true if user opts to continue, disabled or GUI is not present.
    • stopThreads

      public void stopThreads()
      stops all the current threads, to make a restart possible
    • getRevision

      public String getRevision()
      Returns the revision string.
      Specified by:
      getRevision in interface RevisionHandler
      Returns:
      the revision
    • main

      public static void main(String[] args)
      prints only some statistics
      Parameters:
      args - the commandline arguments - ignored