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 阅读(144) 评论(0) 收藏 举报
浙公网安备 33010602011771号