This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: forcing guile to collect *all* garbage?


On Mon, Apr 12, 1999 at 05:27:25PM -0230, Greg Harvey wrote:
> Jon Trowbridge <trow@emccta.com> writes:
> 
> > Is there anything that I can do to trigger an "aggressive" garbage
> > collection in guile, in which the whole heap would be scanned and I
> > could be sure afterwards that every lingering unreferenced object had
> > been deallocated?
> 
> That is how the gc currently operates (though I might not be
> understanding you correctly). If a dead object is hanging around, it
> means that either it's being scanned conservatively,

What does it mean to be "scanned conservatively"?

> or that something
> you don't know about is holding a reference to it (the printer is
> currently very bad in this regard).

Well, here is an example of what I'm talking about.  I have some C
code that handles date math that I've hooked into guile via a smob.
I've hacked that smob to print a message whenever an object is
allocated or freed.  Here is an trivial, annotated example of such an
interaction.

guile> (date 1 1 2000) <== This constructs a date object.
Alloced 0x80b67a8
01/01/2000
guile> (date 1 2 2000)
Alloced 0x80b69a0
01/02/2000
guile> (gc)
Freed 0x80b67a8        <== Our first object was freed.  The second remains.
guile> (date 1 3 2000)
Alloced 0x80b66a8
01/03/2000
guile> (gc)
Freed 0x80b69a0        <== The second object was freed.  The third remains.
guile> (gc)
guile> (gc)
guile> (gc)
guile> (gc)            <== <grumble> I can't get rid of the third object.
guile> (cons 1 2)      <== But if I perform a useless operation that allocates
(1 . 2)                    a new cell...
guile> (gc)
Freed 0x80b66a8        <== ...the third object finally goes away!

This might seem like a minor thing, but it is causing me big problems.
At certain key points in my interfaced C++ code, I need to be able to
put myself into a state where I know that all of the old objects of a
certain type have been freed, so that I can perform some operations
that would cause pointers inside those objects to become "dangling"
and thus unsafe.  But the reference counts on my old objects won't
reliably go to zero, because of lingering guile objects.

If this is being caused by the printer, is there anything that can
reasonably be done about it?

Thanks,
-JT