T:Tstringlist; begin T:=Tstringlist.create; try T.add( ....); finally freeandnil(T); end; end;
Frees an object reference and replaces the reference with nil..procedure FreeAndNil(var Obj);Use FreeAndNil to ensure that a variable is nil after you free the object it references. Pass any variable that represents an object as the Obj parameter.Warning: Do not pass a value for Obj if it is not an instance of TObject or one of its descendants.
begin
T:=Tstringlist.create;
try
T.add( ....);
finally
freeandnil(T);
end;
end;
因为对象被释放时
对象变量这个指针并没有被清空
而且对象所占的内存(非对象指针)并没有被清空
这是Delphi或者操作系统管理内存的问题
对象所占的内存在对象释放时并没有清空
只是被标记为可以使用
其中所包含的内容还在
所以你无法通过其他的办法来判断一个对象是否被释放了。