Lisp HUG Maillist Archive

Garbage collection of foreign references

Folks,

If this has been asked before then please point me to the right place!

Are foreign structure, pointer, etc. references garbage collected
and if so are there GC callbacks?

     Thanks, Joel

--
http://wagerlabs.com/uptick




Re: Garbage collection of foreign references

On Thu, 28 Jul 2005 21:05:22 +0200, Joel Reymont <joelr1@gmail.com> wrote:

> If this has been asked before then please point me to the right
> place!
>
> Are foreign structure, pointer, etc. references garbage collected
> and if so are there GC callbacks?

The short answer is: RTFM... :)

Slightly longer: See for example the WITH-DYNAMIC-FOREIGN-OBJECTS
entry in the FLI manual.  As a general rule, there's no GC for foreign
objects as you usually don't want them to move behind your back.

For GC callbacks (for Lisp objects) see ADD-SPECIAL-FREE-ACTION and
friends.

I think the source code of RDNZL should provide some examples relevant
to your questions.

Cheers,
Edi.


Re: Garbage collection of foreign references

On Fri, 29 Jul 2005 00:13:45 +0200, Joel Reymont <joelr1@gmail.com> wrote:

> Assume that I'm managing a list of external resources (memory
> blocks, etc.)  but they are only used within Lisp. I would like the
> Lisp objects pointing to these resources to be collected when they
> are not referred to any longer.  I suppose that I would use
> add-special-free-action to free the external resources.
>
> Can I do it?

I'm not sure I understand you correctly but I suppose you want to
allocate external resources and "wrap" them with a Lisp object such
that the external resource can only be accessed through this Lisp
object.  So, if the Lisp object is ready to be garbage collected the
external resource can be freed as well.  This can be done with
ADD-SPECIAL-FREE-ACTION.

As I said in my previous email: This is how it is done in RDNZL, look
at the code in container.lisp.

Cheers,
Edi.


Updated at: 2020-12-10 08:51 UTC