Our teacher in the university gave us the following exercise and i have no idea how to process it so if someone could give me a code for this i would be very thankful.
Here is the exercise :
Class Runtime of java.lang package includes some simple methods that can
help you gain a better sense of what the garbage collector of java does.A
Runtime object maintains information about the state of the virtual machine of Java. If you want to
examine this information , you can get the current runtime environment by calling
Static methods getRuntime () and store the result in a variable , like this:
Runtime myRuntime Runtime.getRuntime ();
Once you have this variable you can find how much free memory is available with
call
myRuntime.freeMemory ();
As memory sizes can be large , the return value is the number freeMemory is long instead
for int and indicates the number of byte that are available . You can also explicitly enable the
garbage collector by calling
myRuntime.gc ();
Write a program that distributes 10,000 objects of type Rational without stores them in variables
so that everything becomes waste . After you do , measure the amount of free memory before and
after garbage collection , and use the difference to indicate how many byte released ,
as shown in the following sample :
Allocating 10000 Rational objects
Garbage collection freed 94140