私はインストラクターの好みに応じて acm パッケージのみを使用しています。
このプログラムは、10000 個の有理オブジェクトをガベージになるように割り当て、ガベージ コレクタの使用前後の空きメモリを計算することになっています。次に、ガベージ コレクターがクリアしたメモリの量を出力することになっています。
import acm.program.*;
public class RuntimeGarbage extends ConsoleProgram {
public void run() {
println("Allocating 10000 Rational Objects");
for(int i=1; i==10000; i++) {
new Rational();
}
Runtime myRuntime = Runtime.getRuntime();
long free_before = myRuntime.freeMemory();
myRuntime.gc();
long free_after = myRuntime.freeMemory();
println("Garbage collection freed" + ((free_after)-(free_before)) + "bytes");
}
}
これに関する問題は、コードをコンパイルしようとすると、cmd に次のように表示されることです。
:8: error: cannot find symbol
new Rational();
with an arrow right below the R.
中括弧内のオブジェクトの作成に問題があるのでしょうか?