guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with smobs


From: Mikael Djurfeldt
Subject: Re: Problem with smobs
Date: Tue, 30 May 2006 11:53:34 +0200

On 5/30/06, Joris van der Hoeven <address@hidden> wrote:
Hi all,

I noticed a strange problem with the memory allocation of smobs and
I fail to understand whether I am doing something wrong or whether
this is a bug in Guile.

Consider the (C++) smob code attached below to this message.
All memory allocations are done from within C++, so the free_mysmob
function returns 0. Now consider the following session:

Guile> (define x (mysmob 2))
make smob
Guile> (gc)
mark smob
Guile> (set! x #f)
Guile> (gc)
free smob

So far so good. But now

Guile> (define x (mysmob 2))
make smob
Guile> (begin (display x) (display "\n"))
print smob
#<mysmob 2>
Guile> (set! x #f)
Guile> (gc)
mark smob

In other words: printing the smob prevents the memory from being released.
Does "display" admit some hidden (and undocumented) side effects?
Did I do something wrong? Is this a bug in Guile?
Any help would be appreciated.

I wouldn't call this a bug and wouldn't call it undocumented.  The
garbage collector only guarantees that it doesn't free things which
you can reference.  It doesn't guarantee whether to or when to free
things which lack a reference.

In this case my guess is that some reference to your smob remains on
the stack or in some data structure associated with printing (like the
print-state) immediately after printing.  That reference will very
likely pretty soon disappear after some further execution.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]