java语言的科学与艺术-编程练习7.4
import java.lang.Runtime; import acm.program.*; public class GCTest extends ConsoleProgram { public void run() { Runtime myRuntime = Runtime.getRuntime(); long oldMemory = myRuntime.freeMemory(); for(int i = 0; i < 10000; i++){ new Rational(1); } myRuntime.gc(); long newMemory = myRuntime.freeMemory(); long freeMemory = newMemory - oldMemory; println("Allocating 10000 Rational objects"); println("Garbage collections freed " + freeMemory + " bytes"); } }
posted on 2012-12-30 21:54 mybluecode 阅读(142) 评论(0) 编辑 收藏 举报