[usocket-devel] Re: What if a usocket instance be garbage collected?
Tobias C. Rittweiler
tcr at freebits.de
Wed Oct 1 10:02:30 UTC 2008
"Chun Tian (binghe)" writes
> Hi, usocket devel
>
> If a usocket instance has been garbage collected (or just cannot refer
> to it, i. e. lost it by set the variable to new value), does anyone
> (either usocket or CL platform) will consider closing the correspond
> socket fd automatically?
I think the general consensus is not to misuse the Garbage Collector as
a general ressource manager. You never know when GC is run, if it's run
at all, etc.
In Lisp, automatic ressource deallocation is most often done in the
cleanup clauses of an UNWIND-PROTECT that's nicely abstracted in some
WITH-FOO macro.
> I know at least one CL platform, LispWorks, has some related API
> (HCL:ADD-SPECIAL-FREE-ACTION) [1], and I want to use it in my UDP
> applications. Just don't know if this will be a common feature to be
> considered by usocket itself.
The usual terminology for this kind of stuff is "finalizers". What you
could do, is to add a finalizer that signals a warning if a socket
object is going to be garbage collected that wasn't closed previously.
-T.
More information about the usocket-devel
mailing list