Here you can find the source of waitForMemory(double memory)
Parameter | Description |
---|---|
memory | in MegaBytes units |
public static void waitForMemory(double memory)
//package com.java2s; public class Main { public final static int KILO = 1024; /**//w w w .jav a 2 s . com * Wait till the given requested amount of MegaBytes is free in memory * @param memory in MegaBytes units */ public static void waitForMemory(double memory) { long memoryInBytes = ConvertMegaByteToByte(memory); while (Runtime.getRuntime().freeMemory() < memoryInBytes) { System.gc(); try { Thread.sleep(500); } catch (InterruptedException e1) { e1.printStackTrace(); } } } public static long ConvertMegaByteToByte(double megaByteUnits) { return (long) (megaByteUnits * (KILO * KILO)); } }