下边的代码说明了如何获取当前系统内存信息,这些内存信息可以帮助程序员优化程序代码,很好地解决由于内存不足造成的问题
public static void printMemoryStatistics()
{
Runtime rt=Runtime.getRuntime() ;
System.out.println("***************内存统计***********");
System.out.println("可用内存="+rt.freeMemory());
System.out.println("整个Heap内存="+rt.totalMemory());
System.out.println("使用的内存="+(rt.totalMemory()-rt.freeMemory()) );
System.out.println("*****************************************");