Skip to content
Tristan Hume edited this page Apr 23, 2012 · 3 revisions

#free

##Syntax A freeStatement is:

free [ collectionOrClassId, ] pointerVariableReference

##Description A free statement destroys (deallocates) an element that has been allocated by a new statement.

##Example Using a collection, declare a list of records and allocate one of these records. Then deallocate the record.

    var list : collection of
        record
            contents : string ( 10 )
            next : pointer to list
                        % Short form: next : ^ list
        end record
    var first : pointer to list % Short form: var next : ^ list
    new list, first
            % Allocate an element of list; place its location in first
            % Short form: new first
    �
    free list, first    % Deallocate the element of list located by first
                % Short form: free first

##Details The free statement sets the pointer variable to the nil value. See the new statement for examples of allocating elements of classes and values of types. It the pointer locates a type, the collectionOrClassId in the free statement must be omitted.

An imported class can have one of its objects destroyed (by the free statement) only if the class is imported var.

The collectionOrClassId is optional in the free statement.

##See also class.html and collection.html declarations, the pointer.html type, the new.html statement.html and the nil.html value.

Clone this wiki locally