list of references that do not keep objects alive in javascript
<p>This question is similar to this <a href="http://stackoverflow.com/questions/5119123/weak-reference-in-firefox-javascript-chrome-code">this</a> one, except I do not want to do it in chrome code.</p>

<p>In javascript (running in the browser) I want to keep track of all objects that have been created with a specific construct. Easy, I could do it like this:</p>

<pre><code>var listObjects = [];

function Object() {
  listObjects.push(this);
}

Object.prototype = {
  // class members
}; 
</code></pre>

<p>which is fine, except objects are kept even when they are not used anymore (the garbage collector keeps them because in listObjects there is still a reference) creating memory leaks. Now, I could add a "removeObject" function removing an object from the list, but that would require the user to manually call whenever an objects get out of scope.
Now this could be solved if</p>

<ol>
<li>there would be weak references</li>
<li>one could find out how many references there are to one object</li>
<li>one could define an automatically called destructor</li>
</ol>

<p>Unfortantly, according to my research, none of these exist in javascript (at least not when it is supposed to run in the browser).</p>

<p>Can anyone think of another way of doing this that works in javascript, or some javascript feature that I missed that could be used to do this?</p>
