code: public static String memoryUsage() {
      final Runtime runtime = Runtime.getRuntime();
  
      runtime.gc();
  
      final long max = runtime.maxMemory();
      final long total = runtime.totalMemory();
      final long free = runtime.freeMemory();
      final long used = total - free;
  
      return String.format("%d\t%d\t%d\t%d", max, total, free, used);
    }
docs: Calculates the memory usage according to Runtime.
  
  @return max, total, free and used memory (in bytes)