destructors, how?

Tim Rowledge squeak-dev at lists.squeakfoundation.org
Tue Oct 22 17:02:46 UTC 2002


Bryce Kampjes <bryce at kampjes.demon.co.uk> is claimed by the authorities to have written:

>
> You might want to try using blocks e.g.:
> connectionPooler withConnection: 
>     [:conn| the code that uses the connection "conn"].
> 
> This way the method withConnection: can both open the connection
> and close it. This is a fairly standard idiom to wrap
> creation and deletion of a resource.
Don't forget #ensure: as in
[file _ filename openfile. things doStuff] ensure: [file close]
which will close the file even if the code in the receiver block does a
non-local return.

tim

-- 
Tim Rowledge, tim at sumeru.stanford.edu, http://sumeru.stanford.edu/tim
If only people came with pull-down menus and online help.




More information about the Squeak-dev mailing list