HP Pascal/iX Programmer's Guide (31502-90023)

6- 8
Dispose Procedure
The predefined procedure
dispose
takes a pointer variable as a parameter
and deallocates the dynamic variable that it references. When the
variable is deallocated, it is inaccessible, and the pointer is
undefined. Files in the deallocated space are closed.
The procedure
new
can only reallocate the space that
dispose
has
deallocated if the program contains the compiler option HEAP_DISPOSE. For
more information, refer to the
HP Pascal/iX Reference Manual
or the
HP Pascal/HP-UX Reference Manual
,
depending on your implementation.
It is an error to call
dispose
with a pointer that is:
* Undefined.
* Nil.
* The dynamic variable referenced by a pointer that is the actual
parameter, passed by reference, of a currently executing routine.
* The dynamic variable referenced by a pointer that is in the record
variable list of a currently executing WITH statement.
Example 1
PROGRAM prog;
TYPE
rec = RECORD
f1,f2,f3 : integer;
END;
recptr = ^rec;
VAR
v1,v2,v3,v4,v5 : recptr;
PROCEDURE p (VAR x : rec);
BEGIN
dispose(v4); {illegal -- disposes x's actual parameter}
END;
PROCEDURE q;
BEGIN
dispose(v4); {illegal -- v4^ is in the record variable
list of an active WITH statement}
END;
(
Example is continued on next page
.)
PROCEDURE r (VAR z : recptr);
PROCEDURE s;
BEGIN
dispose(v4); {illegal -- v4^ is the actual parameter for z}
END;
BEGIN
s;
END;
BEGIN
new(v1);
WITH v1^ DO BEGIN
f1 := 0;
f2 := 0;
f3 := 0;
END;
dispose(v1);
dispose(v1); {illegal -- v1 is undefined}
new(v2);
dispose(v2);
new(v3);
v3 := nil;
dispose(v3); {illegal -- v3 is nil}