public class FreeUpMemoryTest
{
- private static final int ONE_MB = 1024 * 1024;
+ private static final int ONE_MB = 1000 * 1000;
/**
* Configure (read-only) Jalview property settings for test
af.closeMenuItem_actionPerformed(true);
/*
- * request garbage collection and allow 1 second for it to complete;
- * NB there is no guarantee when, or whether, it will run!
+ * request garbage collection and wait briefly for it to run;
+ * NB there is no guarantee when, or whether, it will do so
*/
System.gc();
synchronized (this)
{
try
{
- wait(1000);
+ wait(10);
} catch (InterruptedException e)
{
}
}
/*
+ * a second gc() call should not be necessary - but it is!
+ * the test passes with it, and fails without it
+ */
+ System.gc();
+
+ /*
* check used memory is 'reasonably low'
*/
long availableMemory = Runtime.getRuntime().totalMemory() / ONE_MB;
* - identify large objects in the heap and their referers
* - fix code as necessary to null the references on close
*/
- long expectedMax = 100L;
- assertTrue(usedMemory < expectedMax,
- String.format("Used memory %d > %d", usedMemory, expectedMax));
+ long expectedMax = 30L; // typically reports around 25
+ assertTrue(usedMemory < expectedMax, String.format(
+ "Used memory %d should be less than %d", usedMemory,
+ expectedMax));
}
/**
}
/**
- * Generates an alignment (large enough for this test but not so large it is
- * too slow or runs out of memory) and saves it in a temporary file.
+ * Generates an alignment and saves it in a temporary file, to be loaded by
+ * Jalview. We use a peptide alignment (so Conservation and Quality are
+ * calculated), which is wide enough to ensure Consensus, Conservation and
+ * Occupancy have a significant memory footprint (if not removed from the
+ * heap).
*
* @return
* @throws IOException
File f = File.createTempFile("MemoryTest", "fa");
PrintStream ps = new PrintStream(f);
AlignmentGenerator ag = new AlignmentGenerator(false, ps);
- ag.generate(1000, 20000, 0, 10, 15);
+ int width = 100000;
+ int height = 100;
+ ag.generate(width, height, 0, 10, 15);
return f;
}
}