[plt-scheme] ports and garbage collection

From: Doug Orleans (dougo at place.org)
Date: Sat Nov 20 19:13:47 EST 2004

I've been using code like this to make a bunch of XML queries via HTTP POST:

  (read-xml (post-pure-port url query))

Now suddenly I get a "host not found" error, and then "Too many open
files" when I try to open a file to save data.  I thought ports
were closed when garbage collected, but apparently not.  How come?
It seems tedious to have to close ports manually:

  (let ((in (post-pure-port url query)))
    (begin0 (read-xml in)
            (close-input-port in)))

but maybe I'm just spoiled.

--dougo at place.org


Posted on the users mailing list.