Esempio n. 1
0
  private boolean checkAvaliableMemory(int neededMemory, TestResult testResult) {
    if ((ourMode & CHECK_MEMORY) == 0) return true;

    boolean possibleOutOfMemoryError = possibleOutOfMemory(neededMemory);
    if (possibleOutOfMemoryError) {
      tryGc(5);
      possibleOutOfMemoryError = possibleOutOfMemory(neededMemory);
      if (possibleOutOfMemoryError) {
        log("OutOfMemoryError: dumping memory");
        Runtime runtime = Runtime.getRuntime();
        long total = runtime.totalMemory();
        long free = runtime.freeMemory();
        String errorMessage =
            "Too much memory used. Total: "
                + total
                + " free: "
                + free
                + " used: "
                + (total - free)
                + "\n";
        addErrorMessage(testResult, errorMessage);
      }
    }
    return !possibleOutOfMemoryError;
  }
Esempio n. 2
0
 private static boolean possibleOutOfMemory(int neededMemory) {
   Runtime runtime = Runtime.getRuntime();
   long maxMemory = runtime.maxMemory();
   long realFreeMemory = runtime.freeMemory() + (maxMemory - runtime.totalMemory());
   long meg = 1024 * 1024;
   long needed = neededMemory * meg;
   return realFreeMemory < needed;
 }