On Monday 15 September 2008 03:55:06 Robert K. wrote:
2008/9/14 David M. [email protected]:
What is a “finalizer” in this context?
Can they be lambdas/closures? If so, I think I’ve got what I need –
going to be very tricky to get right.
Is it possible to have weak references in Ruby?
Hmm. It mentions WeakRef::RefError. While I’m at it – is it safe to
WeakRefs to see if they’re still alive?
(That is: If the object is gone, will I always get a RefError, or is it
possible to get something undefined or bad/wrong?)
You have to close file handles as well (even if you use the block form
of File.open you take care of this in a way).
The block form of File.open is a good example, though, and it’s also an
which is tolerable, in the common case.
But even here, it might be useful to wrap it in some sort of
garbage-collectable object – assuming collection run on every single
when the program exits.
To be usable, of course, you’d have to force collection to occur when
out of file descriptors, in case one is being held open by an object
hasn’t been collected… right?
It also means that if I’m implementing any kind of library on top of that,
have to force all my users to do the same manual cleanup.
No, because you can make that part of the library. At least you can
built your library in a way that it will invoke a cleanup hook which
you define as empty method for application specific cleanup so users
of the lib do not have to but can add cleanup functionality. Cleanup
of the framework is done automatically of course.
The problem is, with the API that it exposes, I don’t know when to have
framework cleanup, other than when a particular object has no more
references to it. I’m not worried about the app-specific cleanup.
The idea is: Apps can be built as they always were, just some objects
really actors (object + thread). So, where an app would let an object
out of scope (and thus be collected), it can also let an actor fall out
scope (and thus be collected, and have the thread closed, too).
Thanks for your help. I’m probably going to have to spend a few solid
(days?) playing with this to be sure, but it looks like I can build