Mercurial > my-ubiquity-commands
view pseudo-weak-refs/index.html @ 19:900a2fabd11c
Added license block.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sat, 25 Apr 2009 13:40:27 -0700 |
parents | 08bddf757ed8 |
children |
line wrap: on
line source
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" media="all" href="index.css" /> <link rel="commands" href="pseudo-weak-refs.js"/> <title>Pseudo Weak References for Web Content</title> </head> <body> <div id="container"> <div id="content"> <h1>Pseudo Weak References for Web Content</h1> <p>This Ubiquity feed provides pseudo weak reference functionality to web content, for the purpose of making it easier to debug memory management issues. Specifically, it adds two new functions to the global <tt>window</tt> object of all web pages:</p> <ul> <li><tt>PseudoWeakRef(object)</tt> is a constructor that makes a pseudo-weak reference for the object. The returned object has one method, <tt>exists()</tt>, which returns whether or not the referent still exists.</li> <li><tt>forceGC()</tt> forces garbage collection.</li> </ul> <p>Here's some example code:</p> <script id="tests"> function testExistsReturnsFalse() { var object = new Object(); var weak = new PseudoWeakRef(object); // Destroy our one strong reference to the object, leaving it available // for garbage collection. object = null; forceGC(); if (weak.exists()) throw new Error("weak referent should not exist"); } </script> <p>The above source code is actually part of the test suite for this feed. <span id="test-result">If this feed were installed, the suite would run now.</span></p> <p>The source code for this feed can be viewed at <a href="pseudo-weak-refs.js">pseudo-weak-refs.js</a>.</p> </div> <div id="messages"> <span id="tests-failed">The suite was run, but some tests failed.</span> <span id="tests-passed">The suite was run, and all tests passed.</span> </div> </div> <script> function testExistsReturnsTrue() { var object = new Object(); var weak = new PseudoWeakRef(object); forceGC(); if (!weak.exists()) throw new Error("weak referent should exist"); } function onLoad() { function $(id) { return document.getElementById(id); } $("tests").innerHTML = $("tests").innerHTML.slice(1); if (window.PseudoWeakRef && window.forceGC) { try { testExistsReturnsFalse(); testExistsReturnsTrue(); } catch (e) { $("test-result").innerHTML = $("tests-failed").innerHTML; throw e; } $("test-result").innerHTML = $("tests-passed").innerHTML; } } window.addEventListener("load", onLoad, false); </script> </body> </html>