link) that is deliberately NOT marked by the GC, so the referent can be...">link) that is deliberately NOT marked by the GC, so the referent can be...">link) that is deliberately NOT marked by the GC, so the referent can be...">link) that is deliberately NOT marked by the GC, so the referent can be...">

WeakLink

← Reference
Io

C implementation of WeakLink. Holds a single non-owning pointer (DATA(self)->link) that is deliberately NOT marked by the GC, so the referent can be collected even while a WeakLink names it. The mechanism for notification is the IoObject listener list plus the tag's notificationFunc: on setLink, the WeakLink registers as a listener on the target via IoObject_addListener_; when the target is freed, the collector fires IoWeakLink_notification which clears the pointer back to NULL. There is no markFunc registered — that is the whole point. The commented-out writeToStream/readFromStream pair persists WeakLinks by PID (IoObject_pid) so they can be rehydrated through IoState_objectWithPid_.

IoWeakLink_free(self)

Registered as the tag's freeFunc. Unregisters from the target's listener list first, then releases the IoWeakLinkData payload.

IoWeakLink_new(state)

Convenience constructor: look up the WeakLink proto and clone it.

IoWeakLink_newTag(state)

Builds the WeakLink tag. Installs a notificationFunc — unique to WeakLink among the core protos — which fires when a listened-to target is collected. Deliberately registers no markFunc so the link target is never retained by this object.

IoWeakLink_newWithValue_(state, v)

Creates a WeakLink whose target is v. Note this helper stashes v directly without registering as a listener — most callers should use IoWeakLink_rawSetLink instead so collection notification fires.

IoWeakLink_notification(self, notification)

Registered as the tag's notificationFunc. The GC calls this when the target object of this WeakLink is collected; we null out the link pointer so the next `link` query returns nil. The commented- out IoMessage_locals_performOn_ would fire an Io-level callback, left in place as a stub for future support.

IoWeakLink_proto(state)

Creates the WeakLink proto: allocates an empty IoWeakLinkData with link set to NULL, attaches the tag, registers the proto, and installs the Io-visible method table (setLink, link).

IoWeakLink_rawClone(proto)

Registered as the tag's cloneFunc. Fresh clones start with a null link rather than inheriting the proto's target — a WeakLink chained through cloning would otherwise register multiple listeners on one target and break the unregister-on-free invariant.

IoWeakLink_rawStopListening(self)

Removes this WeakLink from the current target's listener list so the collector stops notifying it. Used before rebinding the link and on free — without this, a freed WeakLink could still be notified and dereference its own freed data pointer.

IoWeakLink_readFromStream_(self, stream)

Restores a serialized WeakLink by reading a tagged PID and resolving it against the current IoState's object table. Not currently registered on the tag (see commented-out setup in IoWeakLink_newTag) but kept for potential future persistence layers.