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