Components.utils.getWeakReference

  • Revision slug: Components.utils.getWeakReference
  • Revision title: Components.utils.getWeakReference
  • Revision id: 30894
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment clean up, update for bug 712649; 74 words added

Revision Content

{{ gecko_minversion_header("1.9") }}

This method was introduced in Firefox 3 and is used for obtaining a weak reference for an object. To obtain the object reference, you have to call get() on the resulting object.

In addition, just because get() succeeds doesn't mean your object is valid. It might simply not have been garbage collected yet. You might have to check other aspects of the object (like {{ domxref("Node.parentNode()") }} on a DOM node) to verify the object is truly what you want.

Syntax

weakRef = Components.utils.getWeakReference(obj);

Parameters

obj
The object for which to obtain a weak reference.

{{ gecko_callout_heading("12.0") }}

In Gecko 11.0 {{ geckoRelease("11.0") }}, this method was changed to throw an exception if obj is null. In Gecko 12.0 {{ geckoRelease("12.0") }}, the previous behavior of silently failing has been restored.

{{ languages( { "ja": "ja/Components.utils.getWeakReference" } ) }}

Revision Source

<p>{{ gecko_minversion_header("1.9") }}</p>
<p>This method was introduced in <a href="/en/Firefox_3_for_developers" title="en/Firefox_3_for_developers">Firefox 3</a> and is used for obtaining a weak reference for an object. To obtain the object reference, you have to call <code>get()</code> on the resulting object.</p>
<p>In addition, just because <code>get()</code> succeeds doesn't mean your object is valid. It might simply not have been garbage collected yet. You might have to check other aspects of the object (like {{ domxref("Node.parentNode()") }} on a DOM node) to verify the object is truly what you want.</p>
<h3 id="Syntax">Syntax</h3>
<pre>weakRef = Components.utils.getWeakReference(<em>obj</em>);
</pre>
<h4 id="Parameters">Parameters</h4>
<dl> <dt><code>obj</code></dt> <dd>The object for which to obtain a weak reference.</dd>
</dl>
<div class="geckoVersionNote" style="undefined"> <p>{{ gecko_callout_heading("12.0") }}</p> <p>In Gecko 11.0 {{ geckoRelease("11.0") }}, this method was changed to throw an exception if <code>obj</code> is <code>null</code>. In Gecko 12.0 {{ geckoRelease("12.0") }}, the previous behavior of silently failing has been restored.</p>
</div>
<p>{{ languages( { "ja": "ja/Components.utils.getWeakReference" } ) }}</p>
Revert to this revision