I'm only using the acm package as per my instructor's preference.
This program is supposed to allocate 10000 rational objects so that they will become garbage, and then calculate the free memory before and after the use of the garbage collector. Then, it's supposed to print the amount of memory that the garbage collector has cleared.
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");
}
}
The problem with this, is that when i try to compile the code, the cmd shows the following:
:8: error: cannot find symbol
new Rational();
with an arrow right below the R.
Could it be that the problem is the creation of the objects within the curly brackets?