<%@ page contentType="text/html; charset=GBK"%>
<%
long totalMemory = Runtime.getRuntime().totalMemory();
long freeMemory = Runtime.getRuntime().freeMemory();
long usedMemory = totalMemory - freeMemory;
java.text.NumberFormat format = new java.text.DecimalFormat("###,###");
String memoryInfo="垃圾回收前,内存使用情况为:已用内存/总内存:" + format.format(usedMemory) + "/" + format.format(totalMemory);
System.out.println(memoryInfo);
out.println("<br>");
out.println(memoryInfo);
out.println("<br>");
System.out.println("垃圾回收开始,时间为:"+System.currentTimeMillis());
out.println("垃圾回收开始,时间为:"+System.currentTimeMillis());
System.gc();
totalMemory = Runtime.getRuntime().totalMemory();
freeMemory = Runtime.getRuntime().freeMemory();
usedMemory = totalMemory - freeMemory;
memoryInfo="垃圾回收前,内存使用情况为:已用内存/总内存:" + format.format(usedMemory)+ "/" + format.format(totalMemory);
System.out.println(memoryInfo);
out.println("<br>");
out.println(memoryInfo);
System.out.println("垃圾回收结束,时间为:"+System.currentTimeMillis());
out.println("<br>");
out.println("垃圾回收结束,时间为:"+System.currentTimeMillis());
%>
[color=red]结果为:[/color]
垃圾回收前,内存使用情况为:已用内存/总内存:27,045,560/51,408,896
垃圾回收开始,时间为:1308902698673
垃圾回收前,内存使用情况为:已用内存/总内存:19,768,072/51,408,896
垃圾回收结束,时间为:1308902699023