Hacky weak reference implementation in Guile
Go to file
2024-09-11 22:32:20 -04:00
tests Initial implementation and readme 2024-09-11 21:59:02 -04:00
README.org Well that's a lot simpler 2024-09-11 22:32:20 -04:00
weakref.scm Well that's a lot simpler 2024-09-11 22:32:20 -04:00

Guile Weak References

This is a simple little library that makes use of the weak vector functionality in core Guile to implement weak references, objects which weakly point to other objects.

The interface is very simple:

(make-weakref obj)

  • Create a weak reference, which will not count as a reference, so the object can be garbage collected

(weakref-object ref)

  • Get the object associated with the reference, or #f if it has been garbage collected.

Implementation

This is a very simple implementation (thanks David Thompson for a simpler idea). It simply calls a single- element weak vector a weak reference. Initially this used the weak hash table support but using a weak vector is far simpler and uses less memory.