Help: Garbage Collection


Help is available for each task, or you can go straight to the solution source code.

Task 1

Select "Console" from the "Window" menu to bring up the window that displays standard output. Select "Scrapbook" from the "Window" menu also. The scrapbook can be used to enter and test small code fragments easily and quickly. Orient the two windows so that you can see both easily.
No help for this task.

Task 2

From the "Page" menu, select "Run in...", which allows us to set the context under which our code fragment will run. Because we want the code fragment to know about EchoObject, type in "EchoObject" in the top text field when the dialog box appears. Click OK.
No help for this task.

Task 3

Enter the following text into the visible text area:
EchoObject a,b;
a = new EchoObject("bye");
b = new EchoObject("die");
System.out.println("done");

Your scrapbook should look like this:

Select the entire four lines of code and, from the popup menu (obtained by right mouse clicking), select "Run". Shortly, you should see "done" appear in the standard output pane of the console.


No help for this task.

Task 4

Not immediately, but when VisualAge decides to run the garbage collector, you will see "bye" and "die" appear in the standard output pane of the console. The delay is usually less than a minute.
The console will look similar to the following.

The key ideas to note are that you do not have to collect your own garbage and, consequently, you do not have control over when the system collects your garbage nor in what order the objects are collected. In C or C++, you would have to call free() or delete on the data elements manually.


No help for this task.

Copyright © 1996-1997 MageLang Institute. All Rights Reserved.