form1 的內存釋放(20分)

  • 主题发起人 主题发起人 heyuqing
  • 开始时间 开始时间
H

heyuqing

Unregistered / Unconfirmed
GUEST, unregistred user!
各為高手請教一下
1> form1.close;
2>.form1:=nil
3>.form1.destroy
4>.form1.free
有什么不同
 
form1.free,free方法继承自TObject,在system单元声名如下
procedure TObject.Free;
begin
if Self <> nil then //这是free和destroy的区别
Destroy;
end;
form1.destroy的方法是继承的TCustomForm类,在forms单元声名
destructor TCustomForm.Destroy;
begin
if not (csDestroying in ComponentState) then GlobalNameSpace.BeginWrite;
try
if OldCreateOrder then DoDestroy;
MergeMenu(False);
if HandleAllocated then DestroyWindowHandle;
Screen.RemoveForm(Self);
FCanvas.Free;
FIcon.Free;
FreeAndNil(FActionLists);
inherited Destroy;
finally
GlobalNameSpace.EndWrite;
end;
end;
form1.close方法也是继承TCustomForm类
procedure TCustomForm.Close;
var
CloseAction: TCloseAction;
begin
if fsModal in FFormState then
ModalResult := mrCancel
else
if CloseQuery then
begin
if FormStyle = fsMDIChild then
if biMinimize in BorderIcons then
CloseAction := caMinimize else
CloseAction := caNone
else
CloseAction := caHide;
DoClose(CloseAction);
if CloseAction <> caNone then
if Application.MainForm = Self then Application.Terminate
else if CloseAction = caHide then Hide
else if CloseAction = caMinimize then WindowState := wsMinimized
else Release;
end;
end;
form1:=nil;是好像没有什么用,相当于让form1成为空指针,不会释放内存。
关于close的详细解释,可以检索一下有更详细的说明。
 

Similar threads

D
回复
0
查看
824
DelphiTeacher的专栏
D
D
回复
0
查看
768
DelphiTeacher的专栏
D
D
回复
0
查看
719
DelphiTeacher的专栏
D
后退
顶部