Adriaan van Os wrote:
Frank Heckenbach wrote:
Yes, the two `Dispose's on the same value are a disaster
For that very reason, it is a good idea to call Dispose wrapped:
procedure MyDispose( var thePtr: Pointer); begin if thePtr <> nil then begin Dispose( thePtr); thePtr:= nil end end;
Of course, if the pointer-value (itself) has been copied, it can still be diposed twice. To prevent that, you need a well designed program structure in which it is clear who owns the pointer.
IMHO, in such a design it's usually also clear when to dispose it, so the wrapper might not be needed ...
The above procedure makes memory management easier also.
begin thePtr:= nil;
....
MyDispose( thePtr) end;
GPC allows disposing of nil except in standard modes. Frank -- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/, 7977168E GPC To-Do list, latest features, fixed bugs: http://www.gnu-pascal.de/todo.html GPC download signing key: 51FF C1F0 1A77 C6C2 4482 4DDC 117A 9773 7F88 1707