1
0
Fork 0
cl-sites/guile.html_node/Guardians.html

123 lines
5.8 KiB
HTML
Raw Normal View History

2024-12-17 12:49:28 +01:00
<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This manual documents Guile version 3.0.10.
Copyright (C) 1996-1997, 2000-2005, 2009-2023 Free Software Foundation,
Inc.
Copyright (C) 2021 Maxime Devos
Copyright (C) 2024 Tomas Volf
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
copy of the license is included in the section entitled "GNU Free
Documentation License." -->
<title>Guardians (Guile Reference Manual)</title>
<meta name="description" content="Guardians (Guile Reference Manual)">
<meta name="keywords" content="Guardians (Guile Reference Manual)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content=".texi2any-real">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Memory-Management.html" rel="up" title="Memory Management">
<link href="Weak-References.html" rel="prev" title="Weak References">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
-->
</style>
<link rel="stylesheet" type="text/css" href="https://www.gnu.org/software/gnulib/manual.css">
</head>
<body lang="en">
<div class="subsection-level-extent" id="Guardians">
<div class="nav-panel">
<p>
Previous: <a href="Weak-References.html" accesskey="p" rel="prev">Weak References</a>, Up: <a href="Memory-Management.html" accesskey="u" rel="up">Memory Management and Garbage Collection</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsection" id="Guardians-1"><span>6.17.4 Guardians<a class="copiable-link" href="#Guardians-1"> &para;</a></span></h4>
<p>Guardians provide a way to be notified about objects that would
otherwise be collected as garbage. Guarding them prevents the objects
from being collected and cleanup actions can be performed on them, for
example.
</p>
<p>See R. Kent Dybvig, Carl Bruggeman, and David Eby (1993) &quot;Guardians in
a Generation-Based Garbage Collector&quot;. ACM SIGPLAN Conference on
Programming Language Design and Implementation, June 1993.
</p>
<dl class="first-deffn">
<dt class="deffn" id="index-make_002dguardian"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">make-guardian</strong><a class="copiable-link" href="#index-make_002dguardian"> &para;</a></span></dt>
<dt class="deffnx def-cmd-deffn" id="index-scm_005fmake_005fguardian"><span class="category-def">C Function: </span><span><strong class="def-name">scm_make_guardian</strong> <var class="def-var-arguments">()</var><a class="copiable-link" href="#index-scm_005fmake_005fguardian"> &para;</a></span></dt>
<dd><p>Create a new guardian. A guardian protects a set of objects from
garbage collection, allowing a program to apply cleanup or other
actions.
</p>
<p><code class="code">make-guardian</code> returns a procedure representing the guardian.
Calling the guardian procedure with an argument adds the argument to
the guardian&rsquo;s set of protected objects. Calling the guardian
procedure without an argument returns one of the protected objects
which are ready for garbage collection, or <code class="code">#f</code> if no such object
is available. Objects which are returned in this way are removed from
the guardian.
</p>
<p>You can put a single object into a guardian more than once and you can
put a single object into more than one guardian. The object will then
be returned multiple times by the guardian procedures.
</p>
<p>An object is eligible to be returned from a guardian when it is no
longer referenced from outside any guardian.
</p>
<p>There is no guarantee about the order in which objects are returned
from a guardian. If you want to impose an order on finalization
actions, for example, you can do that by keeping objects alive in some
global data structure until they are no longer needed for finalizing
other objects.
</p>
<p>Being an element in a weak vector, a key in a hash table with weak
keys, or a value in a hash table with weak values does not prevent an
object from being returned by a guardian. But as long as an object
can be returned from a guardian it will not be removed from such a
weak vector or hash table. In other words, a weak link does not
prevent an object from being considered collectible, but being inside
a guardian prevents a weak link from being broken.
</p>
<p>A key in a weak key hash table can be thought of as having a strong
reference to its associated value as long as the key is accessible.
Consequently, when the key is only accessible from within a guardian,
the reference from the key to the value is also considered to be
coming from within a guardian. Thus, if there is no other reference
to the value, it is eligible to be returned from a guardian.
</p></dd></dl>
</div>
<hr>
<div class="nav-panel">
<p>
Previous: <a href="Weak-References.html">Weak References</a>, Up: <a href="Memory-Management.html">Memory Management and Garbage Collection</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>