[squeak-dev] Re: [Pharo-project] #ensure: issues

Igor Stasenko siguctua at gmail.com
Thu Mar 4 23:02:47 UTC 2010

On 4 March 2010 23:41, Levente Uzonyi <leves at elte.hu> wrote:
> On Thu, 4 Mar 2010, Bert Freudenberg wrote:
>> On 04.03.2010, at 21:57, Levente Uzonyi wrote:
>>> On Thu, 4 Mar 2010, Igor Stasenko wrote:
>>>> 2010/3/4 Levente Uzonyi <leves at elte.hu>:
>>>>> Here's a simple example (replace file with any external resource):
>>>>> My process opened a file, a termination block will close it if it's
>>>>> evaluated. If I send #terminate to the process I expect my file to be
>>>>> closed, so I won't leak a file descriptor.
>>>>> If the file can't be closed (aka the termination block raised an error)
>>>>> then
>>>>> there's a serious problem. It doesn't really matter what happens then.
>>>>> But I don't have to try to convince you anymore, because Andreas is
>>>>> about to
>>>>> solve the issue.
>>>> I'm not trying to convince anyone, i just wanted to show you that
>>>> there is no good solution in that plane.
>>>> More workarounds means more code to run (and makes things more complex,
>>>> btw).
>>>> But you will be still unsafe.You will be safe, once you stop relying
>>>> on #ensure: in your code and use different approach.
>>>> As for your example: use weak finalizer to close your file.
>>> I'm about to get rid of the weak finalizer in cases where we know the
>>> exact scope when a file is used (as with #*FileNamed:do:). There's no point
>>> in registering and unregistering a file to the WeakRegistry if #ensure:
>>> closes the file for us at the right time.
>>>> This will make sure that no matter what were happen, you wont leave
>>>> the file open. Working with external resources is a pain. But lets try
>>>> to not poison ourselves with manual resource management, which comes
>>>> from C world.
>>> That's exactly what I'm about to do, keeping the resource management
>>> automatic (from the user POV) while making it fast.
>>> You can read my monologue about these plans here:
>>> http://lists.squeakfoundation.org/pipermail/squeak-dev/2010-February/144993.html
>>> Levente
>> Well, the finalizers are a safety net for file handles only anyway.
>> Developers are advised to close files asap, and any code I have seen at
>> least tries to do that. Why would you want to remove those finalizers?
> There are several places where the files are only closed when no error
> occurs, for example: AIFFFileReader >>
> #readFromFile:mergeIfStereo:skipDataChunk:.
> If an error occurs, the finalizer will close it. There are more than 200
> methods which possibly have the same kind of code.
> I want to remove the registration to the WeakRegistry when a file is opened
> via #*FileNamed:do:, because registering is slow and superfluous because the
> termination block (#ensure:) will close them anyway.
> Currently registering and unregistering takes ~27% of the total time of
> opening and closing a file if the WeakRegistry is almost empty (2 elements).
> If it contains 1002 elements, then registering and unregistering takes ~37%
> of the total time. This could be decreased to 0 in both cases, and the
> number of open files wouldn't affect the performance of file opening and
> closing in this case.

or.. change the VM for better support of finalization. :)

> Levente
>> - Bert -

Best regards,
Igor Stasenko AKA sig.

More information about the Squeak-dev mailing list