731 B
731 B
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.