Created
April 21, 2016 09:43
-
-
Save Zapotek/ebb89c0bd9450f6bbe1e73cad0f9fe85 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
<head> | |
<!-- classpage -- > | |
<!-- RD version: 0.34.2 --> | |
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /> | |
<meta name='description' content=' Module : ObjectSpace - Ruby 2.2.0 ' /> | |
<meta content="2015-10-18 16:42:59 -0500" http-equiv="change-date" /> | |
<!-- rel_prefix = '' ENV['RDOC_FOR_WEBSITE'] = true--> | |
<!-- rel_prefix = '.' asset_rel_prefix = '' --> | |
<title>Module: ObjectSpace (Ruby 2.2.0) </title> | |
<!-- link rel="stylesheet" href=".css/obf.css" --> | |
<link rel="stylesheet" href="/css/inuit.css" > | |
<link rel="stylesheet" href="/css/grid.inuit.css" > | |
<link rel="stylesheet" href="/css/2011.css" type="text/css" > | |
<link rel="stylesheet" href="/css/rdoc.css" type="text/css" > | |
<script src="/js/jquery.js" type="text/javascript" charset="utf-8"></script> | |
<script src="/js/thickbox-compressed.js" type="text/javascript" charset="utf-8"></script> | |
<script src="/js/quicksearch.js" type="text/javascript" charset="utf-8"></script> | |
<script src="/js/rubydoc.js" type="text/javascript" charset="utf-8"></script> | |
<script src="/js/highlight.min.js"></script> | |
<script> | |
hljs.tabReplace = ' '; | |
hljs.initHighlightingOnLoad(); | |
</script> | |
<style type='text/css'> | |
#vulns-alert #vulns{ | |
background-color: #c33 ! important; | |
width: 100%; | |
text-align: center; | |
} | |
#vulns-alert #vulns a { | |
color: #F99 ! important; | |
} | |
</style> | |
</head> | |
<body id="top" class="module rdocstar"> | |
<div id='actionbar' > | |
<div class='wrapper'> | |
<ul class='grids g0'> | |
<li class='grid-2' ><a href='/' target='_top' >Home</a></li> | |
<li class='grid-2' ><a href='/core-2.2.0' target='_top' >Core 2.2.0</a></li> | |
<li class='grid-2' ><a href='/stdlib-2.2.0' target='_top' >Std-lib 2.2.0</a></li> | |
<!-- li class='grid-2' ><a href='/zems' target='_top' >Zems</a></li --> | |
<li class='grid-2' ><a href='/downloads' target='_top' >Downloads</a></li> | |
<li class='grid-5 right' id='rd-action-search'><form id="searchbox_011815814100681837392:wnccv6st5qk" action="http://ruby-doc.com/search.html"><input type="hidden" name="cx" value="011815814100681837392:wnccv6st5qk" ><input id='rd-search-input' name="q" type="text" size="20" >  <input type="submit" name="sa" value="Search" ><input type="hidden" name="cof" value="FORID:9" ></form></li> | |
</ul> | |
</div> | |
<span id='vulns-alert'></span> | |
<!-- VERSION HEADER for 2.2.0 NOT FOUND --></div> <!-- end action bar --> | |
<div class='wrapper'> | |
<div id="metadata"> | |
<div id="home-metadata"> | |
<div id="home-section" class="section"> | |
<h3 class="section-header"> | |
<a href="./index.html">Home</a> | |
<a href="./index.html#classes">Classes</a> | |
<a href="./index.html#methods">Methods</a> | |
<!-- br><a id='alternateFormatLink' class='rotate' href="#" onclick='matchingYardUrl()'>YARD version</a --> | |
</h3> | |
</div> | |
</div> | |
<div id="file-metadata"> | |
<div id="file-list-section" class="section"> | |
<h3 class="section-header">In Files</h3> | |
<div class="section-body"> | |
<ul id='file-metadata'> | |
<li class='in-file'>gc.c</li> | |
</ul> | |
</div> | |
</div> | |
</div> | |
<div id="class-metadata"> | |
<!-- Namespace Contents --> | |
<div id="namespace-list-section" class="section"> | |
<h3 class="section-header">Namespace</h3> | |
<ul class="link-list"> | |
<li><span class="type">CLASS</span> <a href="ObjectSpace/WeakMap.html">ObjectSpace::WeakMap</a></li> | |
</ul> | |
</div> | |
<!-- Method Quickref --> | |
<div id="method-list-section" class="section"> | |
<h3 class="section-header">Methods</h3> | |
<ul class="link-list"> | |
<li><a href="#method-c-_id2ref">::_id2ref</a></li> | |
<li><a href="#method-c-count_objects">::count_objects</a></li> | |
<li><a href="#method-c-define_finalizer">::define_finalizer</a></li> | |
<li><a href="#method-c-each_object">::each_object</a></li> | |
<li><a href="#method-c-garbage_collect">::garbage_collect</a></li> | |
<li><a href="#method-c-undefine_finalizer">::undefine_finalizer</a></li> | |
</ul> | |
</div> | |
</div> | |
<div id="project-metadata"> | |
<div id="fileindex-section" class="section project-section"> | |
<h3 class="section-header">Files</h3> | |
<ul id='files'> | |
<li class="file"><a href="./_lib/racc/rdoc/grammar_en_rdoc.html">grammar.en.rdoc</a></li> | |
<li class="file"><a href="./_test/rdoc/test_ja_rdoc.html">test.ja.rdoc</a></li> | |
<li class="file"><a href="./doc/contributing_rdoc.html">contributing.rdoc</a></li> | |
<li class="file"><a href="./doc/contributors_rdoc.html">contributors.rdoc</a></li> | |
<li class="file"><a href="./doc/dtrace_probes_rdoc.html">dtrace_probes.rdoc</a></li> | |
<li class="file"><a href="./doc/globals_rdoc.html">globals.rdoc</a></li> | |
<li class="file"><a href="./doc/keywords_rdoc.html">keywords.rdoc</a></li> | |
<li class="file"><a href="./doc/maintainers_rdoc.html">maintainers.rdoc</a></li> | |
<li class="file"><a href="./doc/marshal_rdoc.html">marshal.rdoc</a></li> | |
<li class="file"><a href="./doc/regexp_rdoc.html">regexp.rdoc</a></li> | |
<li class="file"><a href="./doc/security_rdoc.html">security.rdoc</a></li> | |
<li class="file"><a href="./doc/standard_library_rdoc.html">standard_library.rdoc</a></li> | |
<li class="file"><a href="./doc/syntax_rdoc.html">syntax.rdoc</a></li> | |
<li class="file"><a href="./doc/syntax/assignment_rdoc.html">assignment.rdoc</a></li> | |
<li class="file"><a href="./doc/syntax/calling_methods_rdoc.html">calling_methods.rdoc</a></li> | |
<li class="file"><a href="./doc/syntax/control_expressions_rdoc.html">control_expressions.rdoc</a></li> | |
<li class="file"><a href="./doc/syntax/exceptions_rdoc.html">exceptions.rdoc</a></li> | |
<li class="file"><a href="./doc/syntax/literals_rdoc.html">literals.rdoc</a></li> | |
<li class="file"><a href="./doc/syntax/methods_rdoc.html">methods.rdoc</a></li> | |
<li class="file"><a href="./doc/syntax/miscellaneous_rdoc.html">miscellaneous.rdoc</a></li> | |
<li class="file"><a href="./doc/syntax/modules_and_classes_rdoc.html">modules_and_classes.rdoc</a></li> | |
<li class="file"><a href="./doc/syntax/precedence_rdoc.html">precedence.rdoc</a></li> | |
<li class="file"><a href="./doc/syntax/refinements_rdoc.html">refinements.rdoc</a></li> | |
<li class="file"><a href="./sample/drb/README_ja_rdoc.html">README.ja.rdoc</a></li> | |
<li class="file"><a href="./sample/drb/README_rdoc.html">README.rdoc</a></li> | |
</ul> | |
</div> | |
<div id="classindex-section" class="section project-section"> | |
<h3 class="section-header">Class/Module Index | |
<span class="search-toggle"><img src="./images/find.png" | |
height="16" width="16" alt="[+]" | |
title="show/hide quicksearch" /></span></h3> | |
<form action="#" method="get" accept-charset="utf-8" class="initially-hidden"> | |
<fieldset> | |
<legend>Quicksearch</legend> | |
<input type="text" name="quicksearch" value="" | |
class="quicksearch-field" /> | |
</fieldset> | |
</form> | |
<ul class="link-list"> | |
<li><a href="./ArgumentError.html">ArgumentError</a></li> | |
<li><a href="./Array.html">Array</a></li> | |
<li><a href="./BasicObject.html">BasicObject</a></li> | |
<li><a href="./Bignum.html">Bignum</a></li> | |
<li><a href="./Binding.html">Binding</a></li> | |
<li><a href="./Class.html">Class</a></li> | |
<li><a href="./Comparable.html">Comparable</a></li> | |
<li><a href="./Complex.html">Complex</a></li> | |
<li><a href="./Complex/compatible.html">Complex::compatible</a></li> | |
<li><a href="./ConditionVariable.html">ConditionVariable</a></li> | |
<li><a href="./Continuation.html">Continuation</a></li> | |
<li><a href="./Data.html">Data</a></li> | |
<li><a href="./Dir.html">Dir</a></li> | |
<li><a href="./ENV.html">ENV</a></li> | |
<li><a href="./EOFError.html">EOFError</a></li> | |
<li><a href="./Encoding.html">Encoding</a></li> | |
<li><a href="./Encoding/CompatibilityError.html">Encoding::CompatibilityError</a></li> | |
<li><a href="./Encoding/Converter.html">Encoding::Converter</a></li> | |
<li><a href="./Encoding/ConverterNotFoundError.html">Encoding::ConverterNotFoundError</a></li> | |
<li><a href="./Encoding/InvalidByteSequenceError.html">Encoding::InvalidByteSequenceError</a></li> | |
<li><a href="./Encoding/UndefinedConversionError.html">Encoding::UndefinedConversionError</a></li> | |
<li><a href="./EncodingError.html">EncodingError</a></li> | |
<li><a href="./Enumerable.html">Enumerable</a></li> | |
<li><a href="./Enumerator.html">Enumerator</a></li> | |
<li><a href="./Enumerator/Generator.html">Enumerator::Generator</a></li> | |
<li><a href="./Enumerator/Lazy.html">Enumerator::Lazy</a></li> | |
<li><a href="./Enumerator/Yielder.html">Enumerator::Yielder</a></li> | |
<li><a href="./Errno.html">Errno</a></li> | |
<li><a href="./Exception.html">Exception</a></li> | |
<li><a href="./FalseClass.html">FalseClass</a></li> | |
<li><a href="./Fiber.html">Fiber</a></li> | |
<li><a href="./FiberError.html">FiberError</a></li> | |
<li><a href="./File.html">File</a></li> | |
<li><a href="./File/Constants.html">File::Constants</a></li> | |
<li><a href="./File/Stat.html">File::Stat</a></li> | |
<li><a href="./FileTest.html">FileTest</a></li> | |
<li><a href="./Fixnum.html">Fixnum</a></li> | |
<li><a href="./Float.html">Float</a></li> | |
<li><a href="./FloatDomainError.html">FloatDomainError</a></li> | |
<li><a href="./GC.html">GC</a></li> | |
<li><a href="./GC/Profiler.html">GC::Profiler</a></li> | |
<li><a href="./Hash.html">Hash</a></li> | |
<li><a href="./IO.html">IO</a></li> | |
<li><a href="./IO/EAGAINWaitReadable.html">IO::EAGAINWaitReadable</a></li> | |
<li><a href="./IO/EAGAINWaitWritable.html">IO::EAGAINWaitWritable</a></li> | |
<li><a href="./IO/EINPROGRESSWaitReadable.html">IO::EINPROGRESSWaitReadable</a></li> | |
<li><a href="./IO/EINPROGRESSWaitWritable.html">IO::EINPROGRESSWaitWritable</a></li> | |
<li><a href="./IO/EWOULDBLOCKWaitReadable.html">IO::EWOULDBLOCKWaitReadable</a></li> | |
<li><a href="./IO/EWOULDBLOCKWaitWritable.html">IO::EWOULDBLOCKWaitWritable</a></li> | |
<li><a href="./IO/WaitReadable.html">IO::WaitReadable</a></li> | |
<li><a href="./IO/WaitWritable.html">IO::WaitWritable</a></li> | |
<li><a href="./IOError.html">IOError</a></li> | |
<li><a href="./IndexError.html">IndexError</a></li> | |
<li><a href="./Integer.html">Integer</a></li> | |
<li><a href="./Interrupt.html">Interrupt</a></li> | |
<li><a href="./Kernel.html">Kernel</a></li> | |
<li><a href="./KeyError.html">KeyError</a></li> | |
<li><a href="./LoadError.html">LoadError</a></li> | |
<li><a href="./LocalJumpError.html">LocalJumpError</a></li> | |
<li><a href="./Marshal.html">Marshal</a></li> | |
<li><a href="./MatchData.html">MatchData</a></li> | |
<li><a href="./Math.html">Math</a></li> | |
<li><a href="./Math/DomainError.html">Math::DomainError</a></li> | |
<li><a href="./Method.html">Method</a></li> | |
<li><a href="./Module.html">Module</a></li> | |
<li><a href="./Mutex.html">Mutex</a></li> | |
<li><a href="./NameError.html">NameError</a></li> | |
<li><a href="./NilClass.html">NilClass</a></li> | |
<li><a href="./NoMemoryError.html">NoMemoryError</a></li> | |
<li><a href="./NoMethodError.html">NoMethodError</a></li> | |
<li><a href="./NotImplementedError.html">NotImplementedError</a></li> | |
<li><a href="./Numeric.html">Numeric</a></li> | |
<li><a href="./Object.html">Object</a></li> | |
<li><a href="./ObjectSpace.html">ObjectSpace</a></li> | |
<li><a href="./ObjectSpace/WeakMap.html">ObjectSpace::WeakMap</a></li> | |
<li><a href="./Proc.html">Proc</a></li> | |
<li><a href="./Process.html">Process</a></li> | |
<li><a href="./Process/GID.html">Process::GID</a></li> | |
<li><a href="./Process/Status.html">Process::Status</a></li> | |
<li><a href="./Process/Sys.html">Process::Sys</a></li> | |
<li><a href="./Process/UID.html">Process::UID</a></li> | |
<li><a href="./Process/Waiter.html">Process::Waiter</a></li> | |
<li><a href="./Queue.html">Queue</a></li> | |
<li><a href="./Random.html">Random</a></li> | |
<li><a href="./Range.html">Range</a></li> | |
<li><a href="./RangeError.html">RangeError</a></li> | |
<li><a href="./Rational.html">Rational</a></li> | |
<li><a href="./Rational/compatible.html">Rational::compatible</a></li> | |
<li><a href="./Regexp.html">Regexp</a></li> | |
<li><a href="./RegexpError.html">RegexpError</a></li> | |
<li><a href="./RubyVM.html">RubyVM</a></li> | |
<li><a href="./RubyVM/Env.html">RubyVM::Env</a></li> | |
<li><a href="./RubyVM/InstructionSequence.html">RubyVM::InstructionSequence</a></li> | |
<li><a href="./RuntimeError.html">RuntimeError</a></li> | |
<li><a href="./ScriptError.html">ScriptError</a></li> | |
<li><a href="./SecurityError.html">SecurityError</a></li> | |
<li><a href="./Signal.html">Signal</a></li> | |
<li><a href="./SignalException.html">SignalException</a></li> | |
<li><a href="./SizedQueue.html">SizedQueue</a></li> | |
<li><a href="./StandardError.html">StandardError</a></li> | |
<li><a href="./StopIteration.html">StopIteration</a></li> | |
<li><a href="./String.html">String</a></li> | |
<li><a href="./Struct.html">Struct</a></li> | |
<li><a href="./Symbol.html">Symbol</a></li> | |
<li><a href="./SyntaxError.html">SyntaxError</a></li> | |
<li><a href="./SystemCallError.html">SystemCallError</a></li> | |
<li><a href="./SystemExit.html">SystemExit</a></li> | |
<li><a href="./SystemStackError.html">SystemStackError</a></li> | |
<li><a href="./Thread.html">Thread</a></li> | |
<li><a href="./Thread/Backtrace/Location.html">Thread::Backtrace::Location</a></li> | |
<li><a href="./ThreadError.html">ThreadError</a></li> | |
<li><a href="./ThreadGroup.html">ThreadGroup</a></li> | |
<li><a href="./Time.html">Time</a></li> | |
<li><a href="./TracePoint.html">TracePoint</a></li> | |
<li><a href="./TrueClass.html">TrueClass</a></li> | |
<li><a href="./TypeError.html">TypeError</a></li> | |
<li><a href="./UnboundMethod.html">UnboundMethod</a></li> | |
<li><a href="./UncaughtThrowError.html">UncaughtThrowError</a></li> | |
<li><a href="./ZeroDivisionError.html">ZeroDivisionError</a></li> | |
<li><a href="./fatal.html">fatal</a></li> | |
<li><a href="./unknown.html">unknown</a></li> | |
</ul> | |
<div id="no-class-search-results" style="display: none;">No matching classes.</div> | |
</div> | |
<div id="debugging-toggle"><img src="./images/bug.png" | |
alt="toggle debugging" height="16" width="16" /></div> | |
</div> | |
</div> <!-- metadata --> | |
<div class='adzbox' id="azk83167"> | |
<div id="carbonads-container"><div class="carbonad"> | |
<script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?zoneid=1673&serve=C6AILKT&placement=rubydocorg" | |
id="_carbonads_js"> | |
</script> | |
<script type="text/javascript" > | |
function c2() { | |
var body = document.body, html = document.documentElement; | |
var height = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight ); | |
var style = document.createElement("style"); | |
style.type = 'text/css'; | |
var t = height/2; | |
if (t < 1000 ) { t = 600 } | |
if (t > 1000 ) { t = 800 } | |
style.innerHTML = " #carbonads_1 { position: absolute ! important; top: " + t + "px; width: 200px; } /* " + height +" */" | |
document.getElementsByTagName('head')[0].appendChild(style); | |
var z = document.createElement("script"); z.type = "text/javascript"; z.async = true; | |
z.src="//cdn.carbonads.com/carbon.js?zoneid=1673&serve=C6AILKT&placement=rubydocorg" ; | |
var s = document.getElementsByTagName("script")[0]; | |
s.parentNode.insertBefore(z, s); | |
} | |
</script> | |
</div></div> | |
<script type="text/javascript"> | |
function checkCarbs() { | |
var searchFor = ".car" + "bona" + "d-tag"; | |
var ctext = $(searchFor); | |
if (!ctext.length ) { | |
// alert("Cannot find element with class " + searchFor ); | |
$("#azcarbon").append("<div class='rd-ab-msg'>If you are running an ad blocker please consider white-listing ruby-doc.org. <br><br>Thank you.</div>"); | |
} | |
} | |
// window.setTimeout(checkCarbs,3000); | |
window.setTimeout(c2, 3000); | |
</script> | |
</div> | |
<div id="documentation"> | |
<h1 class="module">ObjectSpace</h1> | |
<div id="description" class="description"> | |
<p>The <a href="ObjectSpace.html">ObjectSpace</a> module contains a number of | |
routines that interact with the garbage collection facility and allow you | |
to traverse all living objects with an iterator.</p> | |
<p><a href="ObjectSpace.html">ObjectSpace</a> also provides support for object | |
finalizers, procs that will be called when a specific object is about to be | |
destroyed by garbage collection.</p> | |
<pre class="ruby"><span class="ruby-identifier">a</span> = <span class="ruby-string">"A"</span> | |
<span class="ruby-identifier">b</span> = <span class="ruby-string">"B"</span> | |
<span class="ruby-constant">ObjectSpace</span>.<span class="ruby-identifier">define_finalizer</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">proc</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">id</span><span class="ruby-operator">|</span> <span class="ruby-identifier">puts</span> <span class="ruby-node">"Finalizer one on #{id}"</span> }) | |
<span class="ruby-constant">ObjectSpace</span>.<span class="ruby-identifier">define_finalizer</span>(<span class="ruby-identifier">b</span>, <span class="ruby-identifier">proc</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">id</span><span class="ruby-operator">|</span> <span class="ruby-identifier">puts</span> <span class="ruby-node">"Finalizer two on #{id}"</span> }) | |
</pre> | |
<p><em>produces:</em></p> | |
<pre class="ruby"><span class="ruby-constant">Finalizer</span> <span class="ruby-identifier">two</span> <span class="ruby-identifier">on</span> <span class="ruby-value">537763470</span> | |
<span class="ruby-constant">Finalizer</span> <span class="ruby-identifier">one</span> <span class="ruby-identifier">on</span> <span class="ruby-value">537763480</span> | |
</pre> | |
</div><!-- description --> | |
<div id="5Buntitled-5D" class="documentation-section"> | |
<!-- Methods --> | |
<div id="public-class-method-details" class="method-section section"> | |
<h3 class="section-header">Public Class Methods</h3> | |
<div id="_id2ref-method" class="method-detail "> | |
<a name="method-c-_id2ref"></a> | |
<div class="method-heading"> | |
<span class="method-callseq">_id2ref(object_id) → an_object</span> | |
<span class="method-click-advice">click to toggle source</span> | |
</div> | |
<div> | |
<p>Converts an object id to a reference to the object. May not be called on an | |
object id passed as a parameter to a finalizer.</p> | |
<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-string">"I am a string"</span> <span class="ruby-comment">#=> "I am a string"</span> | |
<span class="ruby-identifier">r</span> = <span class="ruby-constant">ObjectSpace</span>.<span class="ruby-identifier">_id2ref</span>(<span class="ruby-identifier">s</span>.<span class="ruby-identifier">object_id</span>) <span class="ruby-comment">#=> "I am a string"</span> | |
<span class="ruby-identifier">r</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">s</span> <span class="ruby-comment">#=> true</span> | |
</pre> | |
<div class="method-source-code" id="_id2ref-source"> | |
<pre> <!-- method.markup_code 290 --> | |
static VALUE | |
id2ref(VALUE obj, VALUE objid) | |
{ | |
#if SIZEOF_LONG == SIZEOF_VOIDP | |
#define NUM2PTR(x) NUM2ULONG(x) | |
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP | |
#define NUM2PTR(x) NUM2ULL(x) | |
#endif | |
rb_objspace_t *objspace = &rb_objspace; | |
VALUE ptr; | |
void *p0; | |
ptr = NUM2PTR(objid); | |
p0 = (void *)ptr; | |
if (ptr == Qtrue) return Qtrue; | |
if (ptr == Qfalse) return Qfalse; | |
if (ptr == Qnil) return Qnil; | |
if (FIXNUM_P(ptr)) return (VALUE)ptr; | |
if (FLONUM_P(ptr)) return (VALUE)ptr; | |
ptr = obj_id_to_ref(objid); | |
if ((ptr % sizeof(RVALUE)) == (4 << 2)) { | |
ID symid = ptr / sizeof(RVALUE); | |
if (rb_id2str(symid) == 0) | |
rb_raise(rb_eRangeError, "%p is not symbol id value", p0); | |
return ID2SYM(symid); | |
} | |
if (!is_id_value(objspace, ptr)) { | |
rb_raise(rb_eRangeError, "%p is not id value", p0); | |
} | |
if (!is_live_object(objspace, ptr)) { | |
rb_raise(rb_eRangeError, "%p is recycled object", p0); | |
} | |
return (VALUE)ptr; | |
} | |
</pre> | |
</div><!-- _id2ref-source --> | |
</div> | |
</div><!-- _id2ref-method --> | |
<div id="count_objects-method" class="method-detail "> | |
<a name="method-c-count_objects"></a> | |
<div class="method-heading"> | |
<span class="method-callseq">count_objects([result_hash]) → hash</span> | |
<span class="method-click-advice">click to toggle source</span> | |
</div> | |
<div> | |
<p>Counts objects for each type.</p> | |
<p>It returns a hash, such as:</p> | |
<pre class="ruby">{ | |
:<span class="ruby-constant">TOTAL=</span><span class="ruby-operator">></span><span class="ruby-value">10000</span>, | |
:<span class="ruby-constant">FREE=</span><span class="ruby-operator">></span><span class="ruby-value">3011</span>, | |
:<span class="ruby-constant">T_OBJECT=</span><span class="ruby-operator">></span><span class="ruby-value">6</span>, | |
:<span class="ruby-constant">T_CLASS=</span><span class="ruby-operator">></span><span class="ruby-value">404</span>, | |
<span class="ruby-comment"># ...</span> | |
} | |
</pre> | |
<p>The contents of the returned hash are implementation specific. It may be | |
changed in future.</p> | |
<p>If the optional argument <code>result_hash</code> is given, it is | |
overwritten and returned. This is intended to avoid probe effect.</p> | |
<p>This method is only expected to work on C Ruby.</p> | |
<div class="method-source-code" id="count_objects-source"> | |
<pre> <!-- method.markup_code 290 --> | |
static VALUE | |
count_objects(int argc, VALUE *argv, VALUE os) | |
{ | |
rb_objspace_t *objspace = &rb_objspace; | |
size_t counts[T_MASK+1]; | |
size_t freed = 0; | |
size_t total = 0; | |
size_t i; | |
VALUE hash; | |
if (rb_scan_args(argc, argv, "01", &hash) == 1) { | |
if (!RB_TYPE_P(hash, T_HASH)) | |
rb_raise(rb_eTypeError, "non-hash given"); | |
} | |
for (i = 0; i <= T_MASK; i++) { | |
counts[i] = 0; | |
} | |
for (i = 0; i < heap_allocated_pages; i++) { | |
struct heap_page *page = heap_pages_sorted[i]; | |
RVALUE *p, *pend; | |
p = page->start; pend = p + page->total_slots; | |
for (;p < pend; p++) { | |
if (p->as.basic.flags) { | |
counts[BUILTIN_TYPE(p)]++; | |
} | |
else { | |
freed++; | |
} | |
} | |
total += page->total_slots; | |
} | |
if (hash == Qnil) { | |
hash = rb_hash_new(); | |
} | |
else if (!RHASH_EMPTY_P(hash)) { | |
st_foreach(RHASH_TBL_RAW(hash), set_zero, hash); | |
} | |
rb_hash_aset(hash, ID2SYM(rb_intern("TOTAL")), SIZET2NUM(total)); | |
rb_hash_aset(hash, ID2SYM(rb_intern("FREE")), SIZET2NUM(freed)); | |
for (i = 0; i <= T_MASK; i++) { | |
VALUE type; | |
switch (i) { | |
#define COUNT_TYPE(t) case (t): type = ID2SYM(rb_intern(#t)); break; | |
COUNT_TYPE(T_NONE); | |
COUNT_TYPE(T_OBJECT); | |
COUNT_TYPE(T_CLASS); | |
COUNT_TYPE(T_MODULE); | |
COUNT_TYPE(T_FLOAT); | |
COUNT_TYPE(T_STRING); | |
COUNT_TYPE(T_REGEXP); | |
COUNT_TYPE(T_ARRAY); | |
COUNT_TYPE(T_HASH); | |
COUNT_TYPE(T_STRUCT); | |
COUNT_TYPE(T_BIGNUM); | |
COUNT_TYPE(T_FILE); | |
COUNT_TYPE(T_DATA); | |
COUNT_TYPE(T_MATCH); | |
COUNT_TYPE(T_COMPLEX); | |
COUNT_TYPE(T_RATIONAL); | |
COUNT_TYPE(T_NIL); | |
COUNT_TYPE(T_TRUE); | |
COUNT_TYPE(T_FALSE); | |
COUNT_TYPE(T_SYMBOL); | |
COUNT_TYPE(T_FIXNUM); | |
COUNT_TYPE(T_UNDEF); | |
COUNT_TYPE(T_NODE); | |
COUNT_TYPE(T_ICLASS); | |
COUNT_TYPE(T_ZOMBIE); | |
#undef COUNT_TYPE | |
default: type = INT2NUM(i); break; | |
} | |
if (counts[i]) | |
rb_hash_aset(hash, type, SIZET2NUM(counts[i])); | |
} | |
return hash; | |
} | |
</pre> | |
</div><!-- count_objects-source --> | |
</div> | |
</div><!-- count_objects-method --> | |
<div id="define_finalizer-method" class="method-detail "> | |
<a name="method-c-define_finalizer"></a> | |
<div class="method-heading"> | |
<span class="method-callseq">define_finalizer(obj, aProc=proc())</span> | |
<span class="method-click-advice">click to toggle source</span> | |
</div> | |
<div> | |
<p>Adds <em>aProc</em> as a finalizer, to be called after <em>obj</em> was | |
destroyed.</p> | |
<div class="method-source-code" id="define_finalizer-source"> | |
<pre> <!-- method.markup_code 290 --> | |
static VALUE | |
define_final(int argc, VALUE *argv, VALUE os) | |
{ | |
VALUE obj, block; | |
rb_scan_args(argc, argv, "11", &obj, &block); | |
should_be_finalizable(obj); | |
if (argc == 1) { | |
block = rb_block_proc(); | |
} | |
else { | |
should_be_callable(block); | |
} | |
return define_final0(obj, block); | |
} | |
</pre> | |
</div><!-- define_finalizer-source --> | |
</div> | |
</div><!-- define_finalizer-method --> | |
<div id="each_object-method" class="method-detail "> | |
<a name="method-c-each_object"></a> | |
<div class="method-heading"> | |
<span class="method-callseq">each_object([module]) {|obj| ... } → fixnum</span> | |
<span class="method-click-advice">click to toggle source</span> | |
</div> | |
<div class="method-heading"> | |
<span class="method-callseq">each_object([module]) → an_enumerator</span> | |
</div> | |
<div> | |
<p>Calls the block once for each living, nonimmediate object in this Ruby | |
process. If <em>module</em> is specified, calls the block for only those | |
classes or modules that match (or are a subclass of) <em>module</em>. | |
Returns the number of objects found. Immediate objects | |
(<code>Fixnum</code>s, <code>Symbol</code>s <code>true</code>, | |
<code>false</code>, and <code>nil</code>) are never returned. In the | |
example below, <code>each_object</code> returns both the numbers we defined | |
and several constants defined in the <code>Math</code> module.</p> | |
<p>If no block is given, an enumerator is returned instead.</p> | |
<pre class="ruby"><span class="ruby-identifier">a</span> = <span class="ruby-value">102.7</span> | |
<span class="ruby-identifier">b</span> = <span class="ruby-value">95</span> <span class="ruby-comment"># Won't be returned</span> | |
<span class="ruby-identifier">c</span> = <span class="ruby-value">12345678987654321</span> | |
<span class="ruby-identifier">count</span> = <span class="ruby-constant">ObjectSpace</span>.<span class="ruby-identifier">each_object</span>(<span class="ruby-constant">Numeric</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">x</span> } | |
<span class="ruby-identifier">puts</span> <span class="ruby-node">"Total count: #{count}"</span> | |
</pre> | |
<p><em>produces:</em></p> | |
<pre class="ruby"><span class="ruby-value">12345678987654321</span> | |
<span class="ruby-value">102.7</span> | |
<span class="ruby-value">2.71828182845905</span> | |
<span class="ruby-value">3.14159265358979</span> | |
<span class="ruby-value">2.22044604925031e-16</span> | |
<span class="ruby-value">1.7976931348623157e+308</span> | |
<span class="ruby-value">2.2250738585072e-308</span> | |
<span class="ruby-constant">Total</span> <span class="ruby-identifier">count</span><span class="ruby-operator">:</span> <span class="ruby-value">7</span> | |
</pre> | |
<div class="method-source-code" id="each_object-source"> | |
<pre> <!-- method.markup_code 290 --> | |
static VALUE | |
os_each_obj(int argc, VALUE *argv, VALUE os) | |
{ | |
VALUE of; | |
if (argc == 0) { | |
of = 0; | |
} | |
else { | |
rb_scan_args(argc, argv, "01", &of); | |
} | |
RETURN_ENUMERATOR(os, 1, &of); | |
return os_obj_of(of); | |
} | |
</pre> | |
</div><!-- each_object-source --> | |
</div> | |
</div><!-- each_object-method --> | |
<div id="garbage_collect-method" class="method-detail "> | |
<a name="method-c-garbage_collect"></a> | |
<div class="method-heading"> | |
<span class="method-callseq">start → nil</span> | |
<span class="method-click-advice">click to toggle source</span> | |
</div> | |
<div class="method-heading"> | |
<span class="method-callseq">garbage_collect → nil</span> | |
</div> | |
<div class="method-heading"> | |
<span class="method-callseq">start(full_mark: true, immediate_sweep: true) → nil</span> | |
</div> | |
<div class="method-heading"> | |
<span class="method-callseq">garbage_collect(full_mark: true, immediate_sweep: true) → nil</span> | |
</div> | |
<div> | |
<p>Initiates garbage collection, unless manually disabled.</p> | |
<p>This method is defined with keyword arguments that default to true:</p> | |
<pre>def GC.start(full_mark: true, immediate_sweep: true); end</pre> | |
<p>Use full_mark: false to perform a minor <a href="GC.html">GC</a>. Use | |
immediate_sweep: false to defer sweeping (use lazy sweep).</p> | |
<p>Note: These keyword arguments are implementation and version dependent. | |
They are not guaranteed to be future-compatible, and may be ignored if the | |
underlying implementation does not support them.</p> | |
<div class="method-source-code" id="garbage_collect-source"> | |
<pre> <!-- method.markup_code 290 --> | |
static VALUE | |
gc_start_internal(int argc, VALUE *argv, VALUE self) | |
{ | |
rb_objspace_t *objspace = &rb_objspace; | |
int full_mark = TRUE, immediate_mark = TRUE, immediate_sweep = TRUE; | |
VALUE opt = Qnil; | |
static ID keyword_ids[3]; | |
rb_scan_args(argc, argv, "0:", &opt); | |
if (!NIL_P(opt)) { | |
VALUE kwvals[3]; | |
if (!keyword_ids[0]) { | |
keyword_ids[0] = rb_intern("full_mark"); | |
keyword_ids[1] = rb_intern("immediate_mark"); | |
keyword_ids[2] = rb_intern("immediate_sweep"); | |
} | |
rb_get_kwargs(opt, keyword_ids, 0, 3, kwvals); | |
if (kwvals[0] != Qundef) full_mark = RTEST(kwvals[0]); | |
if (kwvals[1] != Qundef) immediate_mark = RTEST(kwvals[1]); | |
if (kwvals[2] != Qundef) immediate_sweep = RTEST(kwvals[2]); | |
} | |
garbage_collect(objspace, full_mark, immediate_mark, immediate_sweep, GPR_FLAG_METHOD); | |
if (!finalizing) finalize_deferred(objspace); | |
return Qnil; | |
} | |
</pre> | |
</div><!-- garbage_collect-source --> | |
</div> | |
</div><!-- garbage_collect-method --> | |
<div id="undefine_finalizer-method" class="method-detail "> | |
<a name="method-c-undefine_finalizer"></a> | |
<div class="method-heading"> | |
<span class="method-callseq">undefine_finalizer(obj)</span> | |
<span class="method-click-advice">click to toggle source</span> | |
</div> | |
<div> | |
<p>Removes all finalizers for <em>obj</em>.</p> | |
<div class="method-source-code" id="undefine_finalizer-source"> | |
<pre> <!-- method.markup_code 290 --> | |
static VALUE | |
undefine_final(VALUE os, VALUE obj) | |
{ | |
return rb_undefine_finalizer(obj); | |
} | |
</pre> | |
</div><!-- undefine_finalizer-source --> | |
</div> | |
</div><!-- undefine_finalizer-method --> | |
</div><!-- public-class-method-details --> | |
</div><!-- 5Buntitled-5D --> | |
<div id='tx_ObjectSpace_versioned' class='associated_wrapper'></div><script type='text/javascript'>$("#tx_ObjectSpace_versioned").load("/associated/2.2.0/ObjectSpace.html");</script> <div id='tx_ObjectSpace' class='associated_wrapper'></div><script type='text/javascript'>$("#tx_ObjectSpace").load("/associated/ObjectSpace.html");</script> | |
<!-- disqus ? --> | |
<div class='info'> | |
<p>Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.</p> | |
<p>If you have questions about Ruby or the documentation, please post to one of the <a href='http://www.ruby-lang.org/en/community/mailing-lists/'>Ruby mailing lists</a>. You will get better, faster, help that way.</p> | |
<p>If you wish to post a correction of the docs, please do so, but also <a href='http://bugs.ruby-lang.org' >file bug report</a> so that it can be corrected for the next release. Thank you.</p> | |
<p>If you want to help improve the Ruby documentation, please visit <a href='http://documenting-ruby.org/'>Documenting-ruby.org</a>.</p> | |
</div> | |
</div><!-- documentation --> | |
<div id='dynamic'> | |
</div> | |
<div id="disqus_thread"></div> | |
<script type="text/javascript"> | |
function setDisqusUrl(){ | |
var _loc = window.location.href; | |
disqus_url = _loc.split("?")[0]; | |
} | |
var disqus_url; | |
setDisqusUrl(); | |
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ | |
// var disqus_shortname = 'rubydocbeta'; // required | |
var disqus_shortname = 'ruby-doc'; // required | |
/* * * DON'T EDIT BELOW THIS LINE * * */ | |
(function() { | |
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; | |
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; | |
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); | |
})(); | |
</script> | |
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> | |
<a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a> | |
<div class='grids wrapper' id="footer"> | |
<p><small>This page was generated for Ruby 2.2.0</small></p> | |
<p><a href="http://ruby-doc.org">Ruby-doc.org</a> is a service of <a href="http://jamesbritt.com">James Britt</a> and <a href="http://neurogami.com">Neurogami</a>, a <a href="http://neurogami.com">software development company in Scottsdale, AZ</a>.</p> | |
<p><small>Generated with Ruby-doc Rdoc Generator 0.34.2</small>.</p> | |
</div> | |
</div> | |
<script> | |
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | |
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | |
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | |
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); | |
ga('create', 'UA-335317-2', 'auto'); | |
ga('send', 'pageview'); | |
</script> | |
<script type='text/javascript'> | |
$(document).ready(function() { | |
$.ajaxSetup({ cache: false }); | |
$("#vulns-alert").load("/associated/vulns.html"); | |
}); | |
</script> | |
<script type='text/javascript'> | |
function loadPlus(plusdocs){ | |
// var img_h = $("img.carbonad-image").css('height'); | |
//if(img_h != undefined) { //--- | |
$(plusdocs).find("div[class='associated_wrapper']").each (function() { | |
$("#" + this.id).append($(plusdocs).find("#" + this.id )); | |
}); | |
//} // --- | |
} // end loadPlusdocs | |
function loadInline(json){ | |
for (var lookFor in json) { | |
$(lookFor).after(json[lookFor]); | |
} | |
} // end loadPlusdocs | |
$(document).ready(function() { | |
$.ajaxSetup({ cache: false }); | |
$.get('/associated/2.2.0/plus_ObjectSpace.html', | |
function(plusdocs) { | |
setTimeout(function() { | |
loadPlus(plusdocs); | |
}, 2000); | |
} | |
); | |
$.ajax({ | |
dataType: "json", | |
url: '/associated/2.2.0/inline_ObjectSpace.js', | |
success: function(json) { | |
setTimeout(function() { | |
loadInline(json); | |
}, 2000); | |
} | |
}); | |
}); | |
</script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment