From: Patrick Hurley Date: 2006-06-18T11:36:05+09:00 Subject: Re: cleanup, of sorts On 6/16/06, Eric Hodel wrote: > On Jun 16, 2006, at 7:26 PM, Tom Allison wrote: > > > Is there a method equivelant to perls DESTROY? > > > > I'm trying to clean up database connections that I created with an > > object instantiation but how to I make certain that they are closed > > when the object is out of scope? > > If the DB library writer did their job (and I'm sure they did), they > just are by the GC provided there are no references to them. > > Typically you see code like this when you want to ensure cleanup: > > class IO > def open(filename, mode) > io = new filename, mode > if block_given? then > begin > yield > ensure > io.close unless io.closed? > end > end > return io > end > end > > -- > Eric Hodel - drbrain@segment7.net - http://blog.segment7.net > This implementation is HODEL-HASH-9600 compliant > > http://trackmap.robotcoop.com > > > > Yeah what Eric said. A couple of points: 1. You can't count on garbage collection, for many programs garbage collection may never occur (i.e. you don't exhaust your initial memory pool, before the program completes execution). 2. So always use the block cleanup code, unless you can't :-) pth