Module Weak_pointer

A weak pointer is a pointer to a heap block that does not cause the heap block to remain live during garbage collection.

If the block would otherwise remain live, then the weak pointer remains pointed to the block. If the block is collected, then the weak pointer is cleared.

type 'a t
val sexp_of_t : ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.Sexp.t
val create : Base.unit -> _ t @@ portable

create creates an empty weak pointer. One must set it to point it to something.

val create_full : 'a Heap_block.t -> 'a t @@ portable

create_full is similar to create, but sets the pointer at creation time.

val get : 'a t -> 'a Base.option @@ portable
val get_as_heap_block : 'a t -> 'a Heap_block.t Base.option @@ portable
val is_some : _ t -> Base.bool @@ portable

is_some t = Option.is_some (get t).

val is_none : _ t -> Base.bool @@ portable

is_none t = Option.is_none (get t).

val set : 'a t -> 'a Heap_block.t -> Base.unit @@ portable