37
edits
| Line 24: | Line 24: | ||
* [http://venge.net/graydon/mozilla/nsIClassInfo2.idl nsIClassInfo2.idl]  | * [http://venge.net/graydon/mozilla/nsIClassInfo2.idl nsIClassInfo2.idl]  | ||
* [http://venge.net/graydon/mozilla/nsCycleCollector.cpp nsCycleCollector.cpp]  | * [http://venge.net/graydon/mozilla/nsCycleCollector.cpp nsCycleCollector.cpp]  | ||
* [http://venge.net/graydon/mozilla/nsISupportsImpl.h nsISupportsImpl.h changes]  | |||
Some notes on the implementation:  | |||
* The implementation requires that each participating XPCOM class implement <tt>nsIClassInfo2</tt>. The two methods on this interface must be correct: it is better '''not''' to implement <tt>nsIClassInfo2</tt> than to implement it wrong.  | |||
** <tt>unlink(obj)</tt> should disconnect all outgoing XPCOM references held by <tt>obj</tt>.  | |||
** <tt>traverse(obj,refcount,childcount,children)</tt> should return the refcount for <tt>obj</tt>, as well as the count and an array of outgoing XPCOM references from <tt>obj</tt>.  | |||
* An object implementing <tt>nsIClassInfo2</tt> should also use the <tt>NS_IMPL_CYCLE_COLLECTING_*</tt> macros in the <tt>nsISupportsImpl</tt> header; these implementations hook the appropriate refcount operations to communicate with the global cycle collector.  | |||
* The implementation commandeers a single bit from the refcount stored in <tt>nsAutoRefCnt</tt>. This is not strictly necessary, but should cut down significantly on pointless traffic to the cycle collector.  | |||
* The global cycle collector service is kept as a singleton pointer in <tt>nsAutoRefCnt</tt>. This poses potential problems during shutdown. Advice on how to handle this safely would be appreciated.  | |||
edits