[Gambas-user] Finally/Catch and Return: How is that meant to be used?

Benoît Minisini benoit.minisini at gambas-basic.org
Fri Sep 15 00:21:58 CEST 2023


Le 14/09/2023 à 23:12, Martin Fischer a écrit :
>>
>> But 99% of the time you are supposed to use Gambas objects or strings,
>> whose associated ressources are automatically released.
>>
> 
> Good point. The example that I was working on actually made native
> calls, which means Alloc's and Free's in the Finally block...
> 
> By the way: what about file streams? I would expect that these streams
> have to be closed as soon as possible and reliably, e.g in a Finally
> block in the method that opened it. Right?
> 
> Good night for today,
> Martin
> 

Stream objects are closed when they are freed.

If you create a stream with OPEN in the function, it will be closed when 
it is released, which will happen before the function exits, provided 
that you didn't store a reference on that stream outside of the function.

Regards,

-- 
Benoît Minisini.



More information about the User mailing list