<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="AsciiDoc 8.6.10">
<title>MLtonWeak</title>
<link rel="stylesheet" href="./asciidoc.css" type="text/css">
<link rel="stylesheet" href="./pygments.css" type="text/css">


<script type="text/javascript" src="./asciidoc.js"></script>
<script type="text/javascript">
/*<![CDATA[*/
asciidoc.install();
/*]]>*/
</script>
<link rel="stylesheet" href="./mlton.css" type="text/css">
</head>
<body class="article">
<div id="banner">
<div id="banner-home">
<a href="./Home">MLton 20201002</a>
</div>
</div>
<div id="header">
<h1>MLtonWeak</h1>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">signature</span><span class="w"> </span><span class="n">MLTON_WEAK</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">   </span><span class="k">sig</span><span class="w"></span>
<span class="w">      </span><span class="k">type</span><span class="w"> </span><span class="n">&#39;a</span><span class="w"> </span><span class="n">t</span><span class="w"></span>

<span class="w">      </span><span class="k">val</span><span class="w"> </span><span class="n">get</span><span class="p">:</span><span class="w"> </span><span class="n">&#39;a</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">&#39;a</span><span class="w"> </span><span class="n">option</span><span class="w"></span>
<span class="w">      </span><span class="k">val</span><span class="w"> </span><span class="n">new</span><span class="p">:</span><span class="w"> </span><span class="n">&#39;a</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">&#39;a</span><span class="w"> </span><span class="n">t</span><span class="w"></span>
<span class="w">   </span><span class="k">end</span><span class="w"></span>
</pre></div></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 <span class="monospaced">w: int Weak.t</span>, then
<span class="monospaced">Weak.get w = NONE</span>.</p></div>
<div class="ulist"><ul>
<li>
<p>
<span class="monospaced">type 'a t</span>
</p>
<div class="paragraph"><p>the type of weak pointers to objects of type <span class="monospaced">'a</span></p></div>
</li>
<li>
<p>
<span class="monospaced">get w</span>
</p>
<div class="paragraph"><p>returns <span class="monospaced">NONE</span> if the object pointed to by <span class="monospaced">w</span> no longer exists.
Otherwise, returns <span class="monospaced">SOME</span> of the object pointed to by <span class="monospaced">w</span>.</p></div>
</li>
<li>
<p>
<span class="monospaced">new x</span>
</p>
<div class="paragraph"><p>returns a weak pointer to <span class="monospaced">x</span>.</p></div>
</li>
</ul></div>
</div>
</div>
</div>
<div id="footnotes"><hr></div>
<div id="footer">
<div id="footer-text">
</div>
<div id="footer-badges">
</div>
</div>
</body>
</html>
