⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 garbage-collection.html

📁 自己收集的linux入门到学懂高级编程书集 包括linux程序设计第三版
💻 HTML
字号:
<html lang="en"><head><title>Using the GNU Compiler Collection (GCC)</title><meta http-equiv="Content-Type" content="text/html"><meta name="description" content="Using the GNU Compiler Collection (GCC)"><meta name="generator" content="makeinfo 4.6"><!--Copyright &copy; 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.   <p>Permission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.2 orany later version published by the Free Software Foundation; with theInvariant Sections being "GNU General Public License" and "FundingFree Software", the Front-Cover texts being (a) (see below), and withthe Back-Cover Texts being (b) (see below).  A copy of the license isincluded in the section entitled "GNU Free Documentation License".   <p>(a) The FSF's Front-Cover Text is:   <p>A GNU Manual   <p>(b) The FSF's Back-Cover Text is:   <p>You have freedom to copy and modify this GNU Manual, like GNU     software.  Copies published by the Free Software Foundation raise     funds for GNU development.--><meta http-equiv="Content-Style-Type" content="text/css"><style type="text/css"><!--  pre.display { font-family:inherit }  pre.format  { font-family:inherit }  pre.smalldisplay { font-family:inherit; font-size:smaller }  pre.smallformat  { font-family:inherit; font-size:smaller }  pre.smallexample { font-size:smaller }  pre.smalllisp    { font-size:smaller }--></style></head><body><div class="node"><p>Node:&nbsp;<a name="Garbage%20Collection">Garbage Collection</a>,Next:&nbsp;<a rel="next" accesskey="n" href="Constant-string-objects.html#Constant%20string%20objects">Constant string objects</a>,Previous:&nbsp;<a rel="previous" accesskey="p" href="Type-encoding.html#Type%20encoding">Type encoding</a>,Up:&nbsp;<a rel="up" accesskey="u" href="Objective-C.html#Objective-C">Objective-C</a><hr><br></div><h3 class="section">Garbage Collection</h3><p>Support for a new memory management policy has been added by using apowerful conservative garbage collector, known as theBoehm-Demers-Weiser conservative garbage collector.  It is available from<a href="http://www.hpl.hp.com/personal/Hans_Boehm/gc/">http://www.hpl.hp.com/personal/Hans_Boehm/gc/</a>.   <p>To enable the support for it you have to configure the compiler using anadditional argument, <code>--enable-objc-gc</code>.  You need to havegarbage collector installed before building the compiler.  This willbuild an additional runtime library which has several enhancements tosupport the garbage collector.  The new library has a new name,<code>libobjc_gc.a</code> to not conflict with the non-garbage-collectedlibrary.   <p>When the garbage collector is used, the objects are allocated using theso-called typed memory allocation mechanism available in theBoehm-Demers-Weiser collector.  This mode requires precise information onwhere pointers are located inside objects.  This information is computedonce per class, immediately after the class has been initialized.   <p>There is a new runtime function <code>class_ivar_set_gcinvisible()</code>which can be used to declare a so-called <dfn>weak pointer</dfn>reference.  Such a pointer is basically hidden for the garbage collector;this can be useful in certain situations, especially when you want tokeep track of the allocated objects, yet allow them to becollected.  This kind of pointers can only be members of objects, youcannot declare a global pointer as a weak reference.  Every type which isa pointer type can be declared a weak pointer, including <code>id</code>,<code>Class</code> and <code>SEL</code>.   <p>Here is an example of how to use this feature.  Suppose you want toimplement a class whose instances hold a weak pointer reference; thefollowing class does this:<pre class="smallexample">          @interface WeakPointer : Object     {         const void* weakPointer;     }          - initWithPointer:(const void*)p;     - (const void*)weakPointer;     @end               @implementation WeakPointer          + (void)initialize     {       class_ivar_set_gcinvisible (self, "weakPointer", YES);     }          - initWithPointer:(const void*)p     {       weakPointer = p;       return self;     }          - (const void*)weakPointer     {       return weakPointer;     }          @end          </pre>   <p>Weak pointers are supported through a new type character specifierrepresented by the <code>!</code> character.  The<code>class_ivar_set_gcinvisible()</code> function adds or removes thisspecifier to the string type description of the instance variable namedas argument.   </body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -