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的详细解释,可以检索一下有更详细的说明。