<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 2.0.26">
<title>MLtonWeak</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700">
<link rel="stylesheet" href="./asciidoctor.css">
<link rel="stylesheet" href="./mlton.css">

</head>
<body class="article">
<div id="mlton-header">
<div id="mlton-header-text">
<h2>
<a href="./Home">
MLton
20241230+git20251029+dfsg-5
</a>
</h2>
</div>
</div>
<div id="header">
<h1>MLtonWeak</h1>
</div>
<div id="content">
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="sml">signature MLTON_WEAK =
   sig
      type 'a t

      val get: 'a t -&gt; 'a option
      val new: 'a -&gt; 'a t
   end</code></pre>
</div>
</div>
<div class="paragraph">
<p>A weak pointer is a pointer to an object that is nulled if the object
becomes <a href="Reachability">unreachable</a> due to garbage collection.  The
weak pointer does not itself cause the object it points to be retained
by the garbage collector&#8201;&#8212;&#8201;only other strong pointers can do that.
For objects that are not allocated in the heap, like integers, a weak
pointer will always be nulled.  So, if <code>w: int Weak.t</code>, then
<code>Weak.get w = NONE</code>.</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>type 'a t</code></p>
<div class="paragraph">
<p>the type of weak pointers to objects of type <code>'a</code></p>
</div>
</li>
<li>
<p><code>get w</code></p>
<div class="paragraph">
<p>returns <code>NONE</code> if the object pointed to by <code>w</code> no longer exists.
Otherwise, returns <code>SOME</code> of the object pointed to by <code>w</code>.</p>
</div>
</li>
<li>
<p><code>new x</code></p>
<div class="paragraph">
<p>returns a weak pointer to <code>x</code>.</p>
</div>
</li>
</ul>
</div>
</div>
</body>
</html>