destructors, how?

Joel Shellman joel at ikestrel.com
Sun Jul 13 04:05:09 UTC 2003


There is a way in Java to use WeakReference and ReferenceQueue to detect
connection leaks and such and recover from them. Does Smalltalk have a
similar mechanism?

Thanks,

-joel

----- Original Message ----- 
From: "Lex Spoon" <lex at cc.gatech.edu>
To: <squeak-dev at lists.squeakfoundation.org>
Sent: Tuesday, July 08, 2003 6:34 AM
Subject: Re: destructors, how?


> Ragnar Hojland Espinosa <ragnar at linalco.com> wrote:
> > The thing is.. I'm leaving behind lots open postgres connections which
would
> > be nicely closed with a "destructor", and right now I don't know how to
> > automatically close (maybe you cant?) when it should (the sooner the
> > better). Obviously, postgres complains quite loudly when you have too
many
> > open, and things suddely get very ugly.
> >
> > Ah well.. at least I can add the closes by hand :/  but that means leaks
> > and sort of rules out to have decent db connection pools in any way I
can
> > think of.. so I must be missing something.
>
> Finalization works as well as it can, but unfortunately that isn't
> wonderfully well.  For handling resources other than memory, e.g.
> database connections, it is usually better if you can work out a way to
> do it manually.
>
> In this case, maybe it can be done without needing to put #close's
> everywhere.  Key in on "maintaining a db connection pool".   Make an
> object DBConnectionPool which keeps track of all open connections, and
> have everyone query this object when they want an open connection to
> use.  Have this object periodically check if it has any idle
> connections, and close a few if necessary.  Similarly, have it open a
> few whenever that seems appropriate.
>
> I hope this idea works out for your situation.  I'm sure this idea is
> discussed on the WWW -- it's a common problem!
>
>
> Lex
>



More information about the Squeak-dev mailing list