Why not Free the dialog right now after use?

[expired user #7376]'s profile image [expired user #7376] posted 10 years ago in General Permalink
procedure TMainForm.actSessionManagerExecute(Sender: TObject);
var
Dialog: TConnForm;
begin
Dialog := TConnForm.Create(Self);
Dialog.ShowModal;
// Dialog.Free; // Why not???
end;


procedure TMainForm.actImportCSVExecute(Sender: TObject);
var
Dialog: Tloaddataform;
begin
// Import Textfile
Dialog := Tloaddataform.Create(Self);
Dialog.ShowModal;
end;

---------------------------
Sir, you tool is very good. But sometimes(not little times), it is crashed. So I try to read your code, and I find that you don't free the dialog right now. I think "TConnForm.Create(Self);" means the instance of TConnForm is managed automatically by MainForm and will be free even you have really lost this instance. But why not free the instance right now? It is so easy.
BubikolRamios's profile image BubikolRamios posted 10 years ago Permalink
I think he is aware of programers mantra: "do not repair something that works" (-:

Itherway I remember from head there are also commands like FreeAndNil
that does magic, and only way to confirm (unleas having special tools for looking for memory leaks) that it did what it should is monitoring task manager looking at mem usage.

Time consuming.

Please login to leave a reply, or register at first.