package core_kernel

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

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 then the weak pointer remains pointed to the block. If the block is collected, then the weak pointer is cleared.

type 'a t
include sig ... end
val sexp_of_t : ('a -> Sexplib.Sexp.t) -> 'a t -> Sexplib.Sexp.t
val create : ?thread_safe_after_cleared:(Base.Unit.t -> Base.Unit.t) -> Base.Unit.t -> _ t

create creates an empty weak pointer. One must set it to point it to something. Whenever t is cleared by the garbage collector, thread_safe_after_cleared is called. This happens via a finalizer, so the usual trickiness of finalization applies; see Gc.Expert for more about finalizers.

val get : 'a t -> 'a Base.Heap_block.t Base.Option.t
val is_some : _ t -> Base.Bool.t

is_some t = Option.is_some (get t).

val is_none : _ t -> Base.Bool.t

is_none t = Option.is_none (get t).

val set : 'a t -> 'a Base.Heap_block.t -> Base.Unit.t
OCaml

Innovation. Community. Security.