| Previous | Table of Contents | Next |
Why does dispose mysteriously give me Invalid Pointer Operation errors?
The following source explains more specifically what happens with this error:
program tnt03; uses crt;
{ Demonstration of pointer heap leaks, in a ludicrous,
but easily seen example }
type
intptr = ^integer;
var
a, b: intptr;
begin
new(a);
new(b);
a^ := 2;
b^ := 5;
writeln(Note here that pointer a s contents is , a^);
writeln(and pointer b s contents is , b^);
writeln(When the pointer addresses are exchanged, and not the ,
contents,);
a := b; {address location of pointer a to location of pointer b}
b := a; {inactive, position of pointer a is already pointer b}
writeln(the result is that the contents of pointer a is , a^);
writeln(and the contents of pointer b is , b^);
writeln(This is not desired, as both pointers point to the );
writeln(same address on the heap, one pointer s allocated );
writeln(memory with new() is lost. It can happen );
writeln(inadvertedly, but in most cases where this occurs, );
writeln(it can not be easily seen. A position saved in heap );
writeln(memory should always be removed with dispose. Because );
writeln(this error occurs in this program, the first dispose );
writeln(issued (a) will work properly, but the second dispose );
writeln(will result in the runtime error listing you see
writeln(below: );
highvideo;
writeln(Runtime Error 204: Invalid Pointer Operation);
writeln; writeln;
normvideo;
dispose(a);
dispose(b);
{position with 5 in it is disposed with first call, so 2nd call
results in Runtime Error 204 Invalid Pointer Operation }
end.
Gillin, P. 1995. Give Kahn credit. Computerworld. 29(5):36.
Wirth, N. 1996. Recollections about the development of Pascal. In T. J. Bergin and R. G. Gibson (Eds.), History of Programming Languages. Reading, MA: Addison-Wesley.
| Previous | Table of Contents | Next |