Re: Newbie question about release, freeAndNil, etc



"swansnow" <schultz@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:1125001356.095726.273210@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

> Thank for your thoughtful reply, Rob. A quick question, though. You
> wrote:

>> I recommend you free modal dialogs when ShowModal
>> returns. That means
>> you have code like this:
>
>> LViewerOptions := TFrmViewerOptions.Create(nil);
>> try
>> LViewerOptions.ShowModal;
>> finally
>> LViewerOptions.Free;
>> end;
>
> Are you suggesting that calling release is unnecessary? and doing
> LViewerOptions:= nil is unnecessary a well?

The LViewerOptions variable is used only in this fragment. It's left
to contain a dangling reference, but it's never used again until it
goes out of scope. (It would be a bad habit to do this with global
variables.)


> I'm not really sure what release actually does...

Release _is_ Free. Only it uses a trick to decouple the actual freeing
from the call, so pending Windows messages can be handled. The trick
also involves a Windows message; it waits in line like a good citizen
and causes the form to kill itself only when it's safe.

Groetjes,
Maarten Wiltink


.