[plt-scheme] Collect-Garbage not enabled on Dr. Scheme?

From: Marek Kubica (marek at xivilization.net)
Date: Sun Apr 5 17:55:03 EDT 2009

Hi,

First let me say that I don't know enough on garbage collectors as I
always viewed them from the user perspective, where one just does not
have to care about the garbage generated since someone will clean it up
anyway. A good exercise would be probably implementing a garbage
collector oneself, but I'm not yet up to the task (and except for
learning, see no need for it), but I'll try to answer some of your
questions.

Fortunately this list is also read by the authors of MzScheme and 3m so
they can give you some more information.

On Sun, 5 Apr 2009 19:40:52 +0300
emre berat nebioğlu <beratn at gmail.com> wrote:

> But if we write that function CPS version,tail recursive version
> machine works until finding fact of 50.I mean stack is filled until
> it is full.When it is full,garbage collector starts clearing up that
> stack.

No, not really. A tail call optimized function does not take any
additional space on the stack so it does not fill up. There is no need
to collect garbage in that exact case, since no garbage is created.

> How many stack or heap or register are there in memory ?

There is usually one stack per process. Having multiple stacks (say, 2
times 8 MB) is the same as chaining them into one bigger (1 x 16 MB).
The problem is, that memory is finite so you can't recurse forever
unless you do TCO, since memory runs out - it is that simple.

And registers are not part of the regular memory (RAM), they are built
into your CPU. Depending on your CPU you have more or less registers.
There are also a distinction general purpose registers and special
registers (for example SSE) and especially the old Lisp machines have
some rather unusual registers, as for the standards of today.

> I dont understand shot-living-object and long-living object.I try to
> understand that mail but i am newbie so there are lots of
> foreign thing for me.

Well, short-lived-objects and long-lived-objects are meaningful when
you have a generational GC. Basically, the GC is a program that scans
your whole program memory for unused chunks. As this takes time, it is
often useful to divide the memory into slices for generations.

I'll try to explain it on a short example:

for (i = 0; i < 100; i++)
{
    for (j = 0; j < 100; j++)
    {
        printf("%d %d\n", i, j);
    }
}

You have two loops here and two variables (let's assume they are
objects - in C there are no objects, but I'm speaking about the
concepts), i and j. They are bound to the number objects 0 to 99 but
the outer variable, i changes less often than j. So we put the object i
in the memory slice reserved for generation 0, and j into the memory
slice for generation 1. Now, when we reach the end of the first
iteration of the inner for-loop, we'd like to run the GC. As we assume
to have a generational GC, it only needs to scan the memory slice for
generation 1 leaving the slice of generation 0 alone, thus saving time
that is needed for scanning the memory.
Basically it boils down to this, that the GC does inspect the memory
slices with newer objects more often than the memory slices with older
objects, as newer objects are less likely to be short-lived then older
objects.

> But can queue be used for Garbage collector.I mean instead of Lifo
> using fifo ca be reasonable choice.

No, a garbage collector is an program (or algorithm), a queue is a data
structure.

> Anyway sorry for being busing mailling list.

No problem, the folks here are usually very helpful, so that having a
good mail exchange does not hurt at all.

If you are interested in the topic, you could look at the book
"Structure and Interpretation of Computer Programs", chapter 5 or watch
the SICP videos (especially 9a to 10b).

regards,
Marek


Posted on the users mailing list.