> On May 21, 2023, at 2:47 PM, Michael Van Canneyt via fpc-pascal 
> <fpc-pascal@lists.freepascal.org> wrote:
> 
> Your example will leak memory in any case, even if there is no exception,
> since you're not freeing the object anywhere..

doh, dumb example on my behalf.

> 
> Assuming the result of A is not used outside of Test, the following is the
> only solution:
> 
> procedure Test;
> 
> var
> A : TObject;
> begin
>  A:=TObject.Create;
>  Try
>    // call some code in other unit which raise an exception
>    DoThis;
>  finally
>    A.Free
>  end;
> end;
> 
> You can try to use interfaces, they will be managed by the compiler.

This is what I was worried about, wrapping all functions or needing full ARC on 
all types. Very risk to opt in to this design I would say. I remain not a fan 
of exceptions. :)

Regards,
Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to