On Mon, Aug 31, 2009 at 5:15 PM, Brian Hurt <bhur...@gmail.com> wrote:

> If I recall correctly (and correct me if I'm wrong), Python uses a
> reference counting garbage collector.  Which means as soon as the reference
> to the object goes away, the object gets collected and the handle closed.
> Most JVMs use some form of mark & sweep algorithm, which means it may be
> some time before the object gets collected (and the resource freed).  This
> is especially the case in a generational GC system, where long-lived objects
> get collected much less frequently.  So, for long-running programs, it's
> possible to pile up uncollected resources to the point where you run out of
> the resource, simply because unused objects haven't been collected yet.
>

This suggests that when low-level JVM functions that try to get a file
handle, socket, or what-not from the OS fail they should invoke the garbage
collector in a full stop-the-world collection and then retry, just as the
memory allocator already does, and throw the IOException only if they still
fail afterward. (These resources tend to have finalizers, so the GC should
be run twice back-to-back to collect them, or even repeatedly until no
garbage was collected.)

Then most cases of this would cause the occasional very slow file handle
acquisition instead of a crash or other error.

Generally, when you open a file descriptor, you should always make sure it's
> gets closed when you're done with it.
>

But I do agree with this. Finalizers and gc of objects holding native
resources are a safety net; it's better not to fall into it even when it's
there. You might not die but the judges will be holding up placards reading
0.0, 0.1, 0.0, 1.2, 0.3 or some such after your performance. :)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to