Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Lexical Closures without true Garbage Collection

150 views
Skip to first unread message

Scott

unread,
Oct 8, 2008, 2:43:15 PM10/8/08
to
I was wondering if anyone could point me to articles or web sites that
discuss implementing lexical closures in the absence of true garbage
collection. Perhaps some clever reference counting strategy using
weak references in important places. (I've googled for a day or two,
but I'm not finding too much. Maybe it's not possible...)

Thanks in advance!

Cheers,
-Scott

Jon Harrop

unread,
Oct 8, 2008, 4:25:20 PM10/8/08
to

You can classify closures as downward closures and upward closures. Upward
closures are returned from functions and carry values back up the call
stack, resulting in statically-unbounded value lifetimes and, consequently,
requiring a real GC. In contrast, downward closures are only available to
deeper function calls so they may be stack allocated and do not require a
garbage collector.

Some languages (e.g. Ada) restrict themselves to only downward closures
because they can be implemented without undermining determinism, even if
that means wasted memory.

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?u

George Neuner

unread,
Oct 8, 2008, 4:18:49 PM10/8/08
to
On Wed, 8 Oct 2008 11:43:15 -0700 (PDT), Scott <xsc...@gmail.com>
wrote:

Take a look at region based memory management. Here's a few papers to
get you started: http://www.it-c.dk/research/mlkit/papers.html

George

Scott

unread,
Oct 8, 2008, 6:06:33 PM10/8/08
to
On Oct 8, 1:25 pm, Jon Harrop <j...@ffconsultancy.com> wrote:
>
> You can classify closures as downward closures and upward closures. Upward
> closures are returned from functions and carry values back up the call
> stack, resulting in statically-unbounded value lifetimes and, consequently,
> requiring a real GC. In contrast, downward closures are only available to
> deeper function calls so they may be stack allocated and do not require a
> garbage collector.
>

Upward closures are what I'm interested in, but I'm wondering if there
are any ways to make do without having a true garbage collector. For
example, if you place the restriction that your closure can not be
bound to a location which is reachable from the closure, then you
would not have any reference cycles and could use reference counting.
I'm wondering if there different tricks with perhaps different
restrictions along these lines.

Cheers,
-Scott

Torben Ægidius Mogensen

unread,
Oct 9, 2008, 9:34:44 AM10/9/08
to
Scott <xsc...@gmail.com> writes:

You can do it if you use copying semantics instead of sharing: You
copy the values of the free variables into the closure and return the
full closure on the stack rather than just a pointer to it.

Since closures can have different sizes, you need to store the size of
the closure as its first word, which again requires variable-size
activation records (frames) etc.

Torben

Scott

unread,
Oct 9, 2008, 8:38:24 PM10/9/08
to
On Oct 9, 6:34 am, torb...@pc-003.diku.dk (Torben Ægidius Mogensen)
wrote:

>
> You can do it if you use copying semantics instead of sharing: You
> copy the values of the free variables into the closure and return the
> full closure on the stack rather than just a pointer to it.
>

That would work, but I was hoping to have mutable variables that could
be shared (and that updates to free variables would be visible outside
of the closure). I think George Neuner's list has some promising
stuff on region based allocation that looks promising, but I don't
understand it very well just yet.

Cheers,
-Scott

Waldek Hebisch

unread,
Oct 16, 2008, 8:54:43 PM10/16/08
to

Well, obvious alternative to garbage collection is explicit
deallocation and clearly one can use explicit deallocation
for closures.

It seems that you want garbage collection for closures
"in the absence of true garbage collection". Note that
closures can be used to implement cons cells. So your question
seem to be about garbage collection "in the absence of true
garbage collection" -- there is rich related literature.
Restricting problem to closures does not really change it.

--
Waldek Hebisch
heb...@math.uni.wroc.pl

Scott

unread,
Oct 17, 2008, 12:12:32 PM10/17/08
to
On Oct 16, 5:54 pm, Waldek Hebisch <hebi...@math.uni.wroc.pl> wrote:
>
> It seems that you want garbage collection for closures
> "in the absence of true garbage collection". Note that
> closures can be used to implement cons cells. So your question
> seem to be about garbage collection "in the absence of true
> garbage collection" -- there is rich related literature.
> Restricting problem to closures does not really change it.
>

Yeah, that clicked after I thought about it for a while. Using
closures to implement mutable cons cells is an existence proof that
closures are really full featured objects and therefore a real (not
just reference counting) garbage collector is required in the general
case.

Thanks for the reply though.

Cheers,
-Scott

0 new messages