A weak pointer is a reference to an object that doesn’t prevent
the object from being garbage-collected.
Gauche provides weak pointers as a weak vector object.
A weak vector is like a vector of objects, except each object
can be garbage collected if it is not referenced from objects
other than weak vectors. If the object is collected, the
entry of the weak vector is replaced for
gosh> (define v (make-weak-vector 1)) v gosh> (weak-vector-ref v 0) #f gosh> (weak-vector-set! v 0 (cons 1 1)) #<undef> gosh> (weak-vector-ref v 0) (1 . 1) gosh> (gc) #<undef> gosh> (gc) #<undef> gosh> (weak-vector-ref v 0) #f
The weak vector class. Inherits
so you can use
gauche.collection (see Collection framework) and
gauche.sequence (see Sequence framework).
(coerce-to <weak-vector> '(1 2 3 4)) ⇒ a weak vector with four elements
Creates and returns a weak vector of size size.
Returns the length of a weak vector wvec.
Returns k-th element of a weak vector wvec.
weak-vector-ref signals an error if k is
negative, or greater than or equal to the size of wvec.
However, if an optional argument fallback is given,
it is returned for such case.
If the element has been garbage collected, this procedure returns
fallback if it is provided,
you can also use a method
Sets k-th element of the weak vector wvec to obj. It is an error if k is negative or greater than or equal to the size of wec.