Message> Is the below code a memory leak?

> procedure TSam.Samuel;
> var
>   e: Exception;
> begin
>   e := Exception.Create('Foobar');
> end;

Yes, every time the method is called.

> Is the below code okay?

> procedure TSam.TrySamuel;
> var
>   e: Exception;
> begin
>   e := Exception.Create('Foobar');
>   try
>     //do some stuff
>   finally
>     e.Free;
>   end;
> end;

Okay is subjective.  From a pure coding point of view, as long as "e" is not
used to raise any exceptions inside the try -- finally, the code is OK.
>From a design point of view, it is IMHO, poor practise to create an
exception object and not raise it.  A class should do only one thing and do
it well.  So an exception class should only be used to raise exceptions, and
no more.  Create it when you need to use it.

Dennis.
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to