GCRoots.mesa
Copyright Ó 1993 by Xerox Corporation. All rights reserved.
Created by Christian Jacobi, April 13, 1993 11:08 am PDT
Declaring REFs to be roots for the garbage collector.
This package is useful for the combination of Mesa programs using uncounted zones with Cedar programs using garbage collected heap allocations.
GCRoots: CEDAR DEFINITIONS ~ BEGIN
Combining Mesa programs with Cedar programs is dangerous in the sense that holding a Cedar REF within a data structure in a Mesa uncounted zone is not seen by the garbage collector. The garbage collector might free the object and cause a memory smash. This can be prevented by holding a REF to the Cedar object in a counted place. Such a place might be called a root.
Local variables of a procedure, and, global variables of a Module are "counted" and are always safe to hold Cedar REF's. Usage of GCRoots is necessary only before stashing a Cedar REF into Mesa heap storage.
Include: PROC [x: REF ANY];
Declares x to be a root. Prevents x­ from being garbage collected.
Calls of Include are counted.
Forget: PROC [x: REF ANY];
Forgets that x has been declared a root.
Re-enables garbage collecting of x­ if number of calls to Forget matches number of calls to Include.
Number: PROC [] RETURNS [INT];
Returns number of Cedar REF's retained as roots by this package.
END.