public boolean isOutOfMemory(){
  try {
    Thread.sleep(m_SleepTime);
  }
 catch (  InterruptedException ex) {
    ex.printStackTrace();
  }
  m_MemoryUsage=m_MemoryMXBean.getHeapMemoryUsage();
  if (isEnabled()) {
    long avail=m_MemoryUsage.getMax() - m_MemoryUsage.getUsed();
    if (avail > OUT_OF_MEMORY_THRESHOLD) {
      long num=(avail - OUT_OF_MEMORY_THRESHOLD) / 5242880 + 1;
      m_SleepTime=(long)(2.0 * (Math.log(num) + 2.5));
      if (m_SleepTime > MAX_SLEEP_TIME) {
        m_SleepTime=MAX_SLEEP_TIME;
      }
    }
    return avail < OUT_OF_MEMORY_THRESHOLD;
  }
 else {
    return false;
  }
}

public boolean isOutOfMemory ( ) { try { Thread . sleep ( m_SleepTime ) ; } catch ( InterruptedException ex ) { ex . printStackTrace ( ) ; } m_MemoryUsage = m_MemoryMXBean . getHeapMemoryUsage ( ) ; if ( isEnabled ( ) ) { long avail = m_MemoryUsage . getMax ( ) - m_MemoryUsage . getUsed ( ) ; if ( avail > OUT_OF_MEMORY_THRESHOLD ) { long num = ( avail - OUT_OF_MEMORY_THRESHOLD ) / 5242880 + 1 ; m_SleepTime = ( long ) ( 2.0 * ( Math . log ( num ) + 2.5 ) ) ; if ( m_SleepTime > MAX_SLEEP_TIME ) { m_SleepTime = MAX_SLEEP_TIME ; } } return avail < OUT_OF_MEMORY_THRESHOLD ; } else { return false ; } }
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 .
