[self-interest] simplicity

Michael Latta lattam at mac.com
Wed Jun 30 15:17:11 UTC 2004

The counter point is "don't design it that way".  There is nothing in 
the language that requires you to wait for garbage collection to 
release resources.  In particular if the registry requires you to close 
the accessor before doing something else, by all means close it 
explicitly.  The use of blocks can make the open and/or close 
operations implicit in a custom control structure, or you can do it 
explicitly.  The use of finalizers to release resources is a bad design 
practice in general.


On Jun 29, 2004, at 9:25 PM, Toby Ovod-Everett wrote:

> On Tue, Jun 29, 2004 at 08:23:00PM +1000, Steven Shaw wrote:
>> On Monday 28 June 2004 15:54, Toby Ovod-Everett wrote:
>>> On Sun, Jun 27, 2004 at 08:20:43PM -0700, Michael Latta wrote:
>>> when writing multi-threaded code that I have to worry about race
>>> conditions.  But my instinct is to presume that in single-threaded 
>>> code
>>> that I can forget about them, and that is no longer the case when
>>> deterministic finalization goes out the window.
>> But surely not unless you're going to have a finalisation method 
>> (this assumes
>> that the finalisation will be done on another thread - probably the gc
>> thread). If you write single threaded code and have no need for 
>> finalisation
>> then you still don't need to worry about 
>> race-conditions/non-determinism.
> For instance, say I have a class that interacts with the Windows 
> registry.  In
> one block, I access a key and read through its values.  The block 
> closes and
> then I go to delete the key.  If the finalizer for the object that 
> interacts
> with the key doesn't run before I attempt to delete the key, I will 
> have
> problems because the Windows registry system won't allow deletion of a 
> key for
> which there are open handles.  The requirement that I always 
> explicitly close
> objects to ensure that finalizers run immediately begins to look an 
> awful lot
> like the requirement that I hand back malloc'ed memory . . . :)

More information about the Self-interest mailing list