W wxj9527 Unregistered / Unconfirmed GUEST, unregistred user! 2008-12-22 #1 我理解的是free..释放该对象所在的内存空间.. nil``把该对像的内存空间清空,但对象还在?? 请各位详细讲解下````谢
W wxj9527 Unregistered / Unconfirmed GUEST, unregistred user! 2008-12-22 #3 但我看到有先free再nil的..为何这样一来做? 如何理解free和nil?
L luoyanqing119 Unregistered / Unconfirmed GUEST, unregistred user! 2008-12-22 #4 Use FreeAndNil to ensure that a variable is nil (Delphi) or NULL (C++) after you free the object it references. Pass any variable that represents an object as the Obj parameter. ------------------------delphi是这样说的。
Use FreeAndNil to ensure that a variable is nil (Delphi) or NULL (C++) after you free the object it references. Pass any variable that represents an object as the Obj parameter. ------------------------delphi是这样说的。
L luoyanqing119 Unregistered / Unconfirmed GUEST, unregistred user! 2008-12-22 #5 delphi的系统函数是这样的: procedure FreeAndNil(var Obj); var Temp: TObject; begin Temp := TObject(Obj); Pointer(Obj) := nil; Temp.Free; end;
delphi的系统函数是这样的: procedure FreeAndNil(var Obj); var Temp: TObject; begin Temp := TObject(Obj); Pointer(Obj) := nil; Temp.Free; end;
D delhpi Unregistered / Unconfirmed GUEST, unregistred user! 2008-12-22 #7 以 var Form1:TForm; 为例,我到现在的理解是 form1.free 是释放这个窗口对象所占的内存空间。 form1:=nil 是使Form1这个变量不在指向任何对象。
L luoyanqing119 Unregistered / Unconfirmed GUEST, unregistred user! 2008-12-22 #8 凡是知道1+1=2的人,都会先nil,再free
I iamy Unregistered / Unconfirmed GUEST, unregistred user! 2008-12-22 #10 先nil那么可能导致内存泄露 先free可能导致一个指针无效 看看freeandnil这个函数里面的代码你就知道应该先做哪个后做哪个了
I iamy Unregistered / Unconfirmed GUEST, unregistred user! 2008-12-22 #11 procedure FreeAndNil(var Obj); var Temp: TObject; begin Temp := TObject(Obj); Pointer(Obj) := nil; Temp.Free; end;
procedure FreeAndNil(var Obj); var Temp: TObject; begin Temp := TObject(Obj); Pointer(Obj) := nil; Temp.Free; end;
N newsxy Unregistered / Unconfirmed GUEST, unregistred user! 2008-12-24 #13 Free是释放内存空间,nil是将变量的指针不指向任何地址,如果先nil,还能再Free么?只能是存取违例。正确的做法是先Free再nil,一般用FreeAndNil就可以了。