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?
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?
On Jun 16, 2006, at 7:26 PM, Tom A. 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 H. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant
On 6/16/06, Eric H. [email protected] wrote:
end
Yeah what Eric said. A couple of points:
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).
So always use the block cleanup code, unless you can’t
pth
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs