finalisation

Brent Pinkney brent.pinkney at aircom.co.za
Tue Jan 27 14:04:16 UTC 2004


>> Does this not catch all the possibilities ?
>
> No, of course not. That's why I find the style of putting the resource
> creation inside the ensured block so terribly misleading. It puts you 
> under the impression that you caught all the possibilities, where it is 
> easy to
> see from an example like
>
>     [file := (FileStream newFileNamed: 'foo.bar') halt.
>     ] ensure:[file close].
>
> that you do not catch anything that happens on the right hand side of the
> assignment. IOW, execute the above and close the resulting debugger - it
> will end up with a DNU for file close which illustrates that - although 
> the
> file has been created - it is not being cleaned up after encountering the
> halt.

Ahhh - I think a light has just gone on.

Am I correct in understanding that the assignment operator should instead 
be thought of as a function call (as it can be in C++) which itself can 
fail AFTER the rhs has been sucessfully evaluated but before the lhs has 
been set to point to the result of said rhs computation ?

In the above example, the rhs whould have created a file but the lhs 
(file) would never be set to reference it.

So the ensure: block would have no reference to the file which still needs 
to be closed.

Keeps one sharp, this mailing list :)





More information about the Squeak-dev mailing list