Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

165 linhas
6.7KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Garbage Collection (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="Garbage Collection (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="Garbage Collection (Using the GNU Compiler Collection (GCC))">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Objective_002dC.html#Objective_002dC" rel="up" title="Objective-C">
  30. <link href="Constant-string-objects.html#Constant-string-objects" rel="next" title="Constant string objects">
  31. <link href="Method-signatures.html#Method-signatures" rel="prev" title="Method signatures">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style: oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Garbage-Collection"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Constant-string-objects.html#Constant-string-objects" accesskey="n" rel="next">Constant string objects</a>, Previous: <a href="Type-encoding.html#Type-encoding" accesskey="p" rel="prev">Type encoding</a>, Up: <a href="Objective_002dC.html#Objective_002dC" accesskey="u" rel="up">Objective-C</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  65. </div>
  66. <hr>
  67. <a name="Garbage-Collection-1"></a>
  68. <h3 class="section">8.4 Garbage Collection</h3>
  69. <p>This section is specific for the GNU Objective-C runtime. If you are
  70. using a different runtime, you can skip it.
  71. </p>
  72. <p>Support for garbage collection with the GNU runtime has been added by
  73. using a powerful conservative garbage collector, known as the
  74. Boehm-Demers-Weiser conservative garbage collector.
  75. </p>
  76. <p>To enable the support for it you have to configure the compiler using
  77. an additional argument, <samp><span class="nolinebreak">--enable-objc-gc</span></samp><!-- /@w -->. This will
  78. build the boehm-gc library, and build an additional runtime library
  79. which has several enhancements to support the garbage collector. The
  80. new library has a new name, <samp>libobjc_gc.a</samp> to not conflict with
  81. the non-garbage-collected library.
  82. </p>
  83. <p>When the garbage collector is used, the objects are allocated using the
  84. so-called typed memory allocation mechanism available in the
  85. Boehm-Demers-Weiser collector. This mode requires precise information on
  86. where pointers are located inside objects. This information is computed
  87. once per class, immediately after the class has been initialized.
  88. </p>
  89. <p>There is a new runtime function <code>class_ivar_set_gcinvisible()</code>
  90. which can be used to declare a so-called <em>weak pointer</em>
  91. reference. Such a pointer is basically hidden for the garbage collector;
  92. this can be useful in certain situations, especially when you want to
  93. keep track of the allocated objects, yet allow them to be
  94. collected. This kind of pointers can only be members of objects, you
  95. cannot declare a global pointer as a weak reference. Every type which is
  96. a pointer type can be declared a weak pointer, including <code>id</code>,
  97. <code>Class</code> and <code>SEL</code>.
  98. </p>
  99. <p>Here is an example of how to use this feature. Suppose you want to
  100. implement a class whose instances hold a weak pointer reference; the
  101. following class does this:
  102. </p>
  103. <div class="smallexample">
  104. <pre class="smallexample">
  105. @interface WeakPointer : Object
  106. {
  107. const void* weakPointer;
  108. }
  109. - initWithPointer:(const void*)p;
  110. - (const void*)weakPointer;
  111. @end
  112. @implementation WeakPointer
  113. + (void)initialize
  114. {
  115. if (self == objc_lookUpClass (&quot;WeakPointer&quot;))
  116. class_ivar_set_gcinvisible (self, &quot;weakPointer&quot;, YES);
  117. }
  118. - initWithPointer:(const void*)p
  119. {
  120. weakPointer = p;
  121. return self;
  122. }
  123. - (const void*)weakPointer
  124. {
  125. return weakPointer;
  126. }
  127. @end
  128. </pre></div>
  129. <p>Weak pointers are supported through a new type character specifier
  130. represented by the &lsquo;<samp>!</samp>&rsquo; character. The
  131. <code>class_ivar_set_gcinvisible()</code> function adds or removes this
  132. specifier to the string type description of the instance variable named
  133. as argument.
  134. </p>
  135. <hr>
  136. <div class="header">
  137. <p>
  138. Next: <a href="Constant-string-objects.html#Constant-string-objects" accesskey="n" rel="next">Constant string objects</a>, Previous: <a href="Type-encoding.html#Type-encoding" accesskey="p" rel="prev">Type encoding</a>, Up: <a href="Objective_002dC.html#Objective_002dC" accesskey="u" rel="up">Objective-C</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  139. </div>
  140. </body>
  141. </html>