next up previous contents
Next: Internal Variables Up: Communicating with the Operating Previous: Operating System Commands

Garbage Collection

During a computation, Darwin generates many scratch work expressions which the user never sees directly (they only see the final result of the statement they submitted). Over the course of a session, the memory needed for these computations can become very large. This, in turn, can cause your system to act sluggish. Fortunately, the memory used by these scratch work expressions is recyclable. Entering the statement

> gc();
tells Darwin to immediately coalesce all unused memory space. This can be a costly operation as Darwin must essentially travel through the entire chunk of allocated memory searching for fragments. By default, Darwin performs a garbage collection operation each time a program uses 250,000 words of memory. This can be changed by using the Set command and the internal variable gc (see § [*]).
> Set(gc=500000);            # garbage collection every 500,000 
>                            #   words allocated
The increment (in this case 500,000) specifies how many words must be allocated before Darwin performs a garbage collection. For most small applications, users need never worry about setting the gc variable but if you should notice that your program is using an amount of space close to the total offered by the system, it is prudent to set gc lower than the default value or to explicitly include gc statements in your programs.

To suppress the garbage collection information Darwin displays, one must set the internal variable printgc to false.

> Set(printgc=false);       # suppress garbage collection messages


next up previous contents
Next: Internal Variables Up: Communicating with the Operating Previous: Operating System Commands
Gaston Gonnet
1998-09-15