Issue 2: Add support for cross-language cyclic GC
Status:  Accepted
Owner:
Project Member Reported by var...@gmail.com, Sep 5, 2009
As noted in the "Challenges" section of the current revision of the
documentation, detecting reference cycles between Python and JS-land isn't
currently supported, and as a result it's easy to introduce memory leaks
into a program that uses Pydermonkey.
Sep 5, 2009
Project Member #1 var...@gmail.com
Since Python already has a cycle detector, it'd be nice if we could leverage this. 
One way to do it might be:

Whenever Python's cyclic GC starts to run, make it call our callback (if this is even
possible--if it's not possible, we'll have to manually call this function and invoke
Python GC ourselves). When our callback is called, do the following:

  1. Make a list of what JS runtimes are inactive.
  2. Trace through each runtime, creating a table of how connected their
Python-exposed JS objects are to each other.
  3. Temporarily increase the reference counts of each Python-exposed JS object to
reflect the other Python-exposed JS objects it's connected to. Let these
Python-exposed JS objects have access to the list of objects they're connected to, so
that their tp_traverse callback can properly direct Python's cyclic GC to these objects.
  4. Allow Python's cyclic GC to proceed.
  5. If a Python-exposed JS object's tp_clear callback is called, then it should
decrease its reference counts to all objects it refers to.
  6. When Python's cyclic GC is done, "undo" any temporary incrementing done in #3
that has not yet been undone.