rdf-hashtable
author Benjamin Smedberg <benjamin@smedbergs.us>
Sat, 26 Jul 2008 22:49:39 -0400
changeset 167 a4da40849f5436e629c5732f4368c6c48189637f
parent 113 f52b9eb1520af03948836535a37e522f93b2100c
permissions -rw-r--r--
State as of now

diff --git a/rdf/base/idl/nsIRDFResource.idl b/rdf/base/idl/nsIRDFResource.idl
--- a/rdf/base/idl/nsIRDFResource.idl
+++ b/rdf/base/idl/nsIRDFResource.idl
@@ -65,13 +65,6 @@ interface nsIRDFResource : nsIRDFNode {
     [noscript] void GetValueConst([shared] out string aConstValue);
 
     /**
-     * This method is called by the nsIRDFService after constructing
-     * a resource object to initialize it's URI. You would not normally
-     * call this method directly
-     */
-    void Init(in string uri);
-
-    /**
      * Determine if the resource has the given URI.
      */
     boolean EqualsString(in string aURI);
diff --git a/rdf/base/idl/nsIRDFService.idl b/rdf/base/idl/nsIRDFService.idl
--- a/rdf/base/idl/nsIRDFService.idl
+++ b/rdf/base/idl/nsIRDFService.idl
@@ -88,66 +88,16 @@ interface nsIRDFService : nsISupports {
     boolean IsAnonymousResource(in nsIRDFResource aResource);
 
     /**
-     * Registers a resource with the RDF system, making it unique w.r.t.
-     * GetResource.
-     *
-     * An implementation of nsIRDFResource should call this in its
-     * Init() method if it wishes the resource to be globally unique
-     * (which is usually the case).
-     *
-     * @note that the resource will <i>not</i> be ref-counted by the
-     * RDF service: the assumption is that the resource implementation
-     * will call nsIRDFService::UnregisterResource() when the last
-     * reference to the resource is released.
-     *
-     * @note that the nsIRDFService implementation may choose to
-     * maintain a reference to the resource's URI; therefore, the
-     * resource implementation should ensure that the resource's URI
-     * (accessible via nsIRDFResource::GetValue(const char* *aURI)) is
-     * valid before calling RegisterResource(). Furthermore, the
-     * resource implementation should ensure that this pointer
-     * <i>remains</i> valid for the lifetime of the resource. (The
-     * implementation of the resource cache in nsIRDFService uses the
-     * URI maintained "internally" in the resource as a key into the
-     * cache rather than copying the resource URI itself.)
-     */
-    void RegisterResource(in nsIRDFResource aResource, in boolean aReplace);
-
-    /**
-     * Called to notify the resource manager that a resource is no
-     * longer in use. This method should only be called from the
-     * destructor of a "custom" resource implementation to notify the
-     * RDF service that the last reference to the resource has been
-     * released, so the resource is no longer valid.
-     *
-     * @note As mentioned in nsIRDFResourceFactory::CreateResource(),
-     * the RDF service will use the result of
-     * nsIRDFResource::GetValue() as a key into its cache. For this
-     * reason, you must always un-cache the resource <b>before</b>
-     * releasing the storage for the <code>const char*</code> URI.
-     */
-    void UnregisterResource(in nsIRDFResource aResource);
-
-    /**
      * Register a <i>named data source</i>. The RDF service will call
      * <code>nsIRDFDataSource::GetURI()</code> to determine the URI under
      * which to register the data source.
      *
-     * @note that the data source will <i>not</i> be refcounted by the
-     * RDF service! The assumption is that an RDF data source
-     * registers with the service once it is initialized (via
-     * <code>nsIRDFDataSource::Init()</code>), and unregisters when the
-     * last reference to the data source is released.
+     * @note that the data source will <i>not</i> be rooted by the
+     * RDF service. If a datasource wishes to be long-lived, it should
+     * ensure that it is rooted using other means.
      */
     void RegisterDataSource(in nsIRDFDataSource aDataSource,
                             in boolean          aReplace);
-
-    /**
-     * Unregister a <i>named data source</i>. The RDF service will call
-     * <code>nsIRDFDataSource::GetURI()</code> to determine the URI under which the
-     * data source was registered.
-     */
-    void UnregisterDataSource(in nsIRDFDataSource aDataSource);
 
     /**
      * Get the <i>named data source</i> corresponding to the URI. If a data
diff --git a/rdf/base/src/Makefile.in b/rdf/base/src/Makefile.in
--- a/rdf/base/src/Makefile.in
+++ b/rdf/base/src/Makefile.in
@@ -60,7 +60,6 @@ CPPSRCS		= \
 		rdfTriplesSerializer.cpp \
 		nsCompositeDataSource.cpp \
 		nsContainerEnumerator.cpp \
-		nsDefaultResourceFactory.cpp \
 		nsInMemoryDataSource.cpp \
 		nsNameSpaceMap.cpp \
 		nsRDFContentSink.cpp \
diff --git a/rdf/base/src/nsRDFService.cpp b/rdf/base/src/nsRDFService.cpp
--- a/rdf/base/src/nsRDFService.cpp
+++ b/rdf/base/src/nsRDFService.cpp
@@ -89,6 +89,7 @@
 #include "nsCRT.h"
 #include "nsCRTGlue.h"
 #include "prbit.h"
+#include "nsRDFResource.h"
 
 ////////////////////////////////////////////////////////////////////////
 
@@ -154,6 +155,15 @@ DataSourceFreeEntry(void *pool, PLHashEn
     }
 }
 
+static PRIntn
+DataSourceSweepDying(PLHashEntry *he, PRIntn i, void *arg)
+{
+    if (he->value && !NS_GetGC()->GetMark(he->value))
+        return HT_ENUMERATE_REMOVE;
+
+    return HT_ENUMERATE_NEXT;
+}
+
 static PLHashAllocOps dataSourceHashAllocOps = {
     DataSourceAllocTable, DataSourceFreeTable,
     DataSourceAllocEntry, DataSourceFreeEntry
@@ -197,6 +207,17 @@ static PLDHashTableOps gResourceTableOps
     nsnull
 };
 
+static PLDHashOperator
+ResourceTableSweepDying(PLDHashTable *table, PLDHashEntryHdr *hdr,
+                        PRUint32 number, void *arg)
+{
+    ResourceHashEntry *entry = static_cast<ResourceHashEntry*>(hdr);
+    if (entry->mResource && !NS_GetGC()->GetMark(entry->mResource))
+        return PL_DHASH_REMOVE;
+
+    return PL_DHASH_NEXT;
+}
+
 // ----------------------------------------------------------------------
 //
 // For the mLiterals hashtable.
@@ -235,6 +256,17 @@ static PLDHashTableOps gLiteralTableOps 
     nsnull
 };
 
+static PLDHashOperator
+LiteralTableSweepDying(PLDHashTable *table, PLDHashEntryHdr *hdr,
+                       PRUint32 number, void *arg)
+{
+    LiteralHashEntry *entry = static_cast<LiteralHashEntry*>(hdr);
+    if (entry->mLiteral && !NS_GetGC()->GetMark(entry->mLiteral))
+        return PL_DHASH_REMOVE;
+
+    return PL_DHASH_NEXT;
+}
+
 // ----------------------------------------------------------------------
 //
 // For the mInts hashtable.
@@ -271,6 +303,17 @@ static PLDHashTableOps gIntTableOps = {
     PL_DHashFinalizeStub,
     nsnull
 };
+
+static PLDHashOperator
+IntTableSweepDying(PLDHashTable *table, PLDHashEntryHdr *hdr,
+                   PRUint32 number, void *arg)
+{
+    IntHashEntry *entry = static_cast<IntHashEntry*>(hdr);
+    if (entry->mInt && !NS_GetGC()->GetMark(entry->mInt))
+        return PL_DHASH_REMOVE;
+
+    return PL_DHASH_NEXT;
+}
 
 // ----------------------------------------------------------------------
 //
@@ -318,7 +361,18 @@ static PLDHashTableOps gDateTableOps = {
     nsnull
 };
 
-class BlobImpl : public MMgc::GCFinalizedObject, public nsIRDFBlob
+static PLDHashOperator
+DateTableSweepDying(PLDHashTable *table, PLDHashEntryHdr *hdr,
+                    PRUint32 number, void *arg)
+{
+    DateHashEntry *entry = static_cast<DateHashEntry*>(hdr);
+    if (entry->mDate && !NS_GetGC()->GetMark(entry->mDate))
+        return PL_DHASH_REMOVE;
+
+    return PL_DHASH_NEXT;
+}
+
+class BlobImpl : public MMgc::GCObject, public nsIRDFBlob
 {
 public:
     struct Data {
@@ -336,12 +390,6 @@ public:
         mData.mLength = aLength;
         mData.mBytes = mBytes;
         memcpy(mBytes, aBytes, aLength);
-        RDFServiceImpl::gRDFService->RegisterBlob(this);
-    }
-
-    ~BlobImpl()
-    {
-        RDFServiceImpl::gRDFService->UnregisterBlob(this);
     }
 
     NS_DECL_ISUPPORTS
@@ -357,7 +405,7 @@ NS_IMETHODIMP
 NS_IMETHODIMP
 BlobImpl::EqualsNode(nsIRDFNode *aNode, PRBool *aEquals)
 {
-    nsCOMPtr<nsIRDFBlob> blob = do_QueryInterface(aNode);
+    nsIRDFBlob* blob = do_QueryInterface(aNode);
     if (blob) {
         PRInt32 length;
         blob->GetLength(&length);
@@ -440,6 +488,17 @@ static PLDHashTableOps gBlobTableOps = {
     nsnull
 };
 
+static PLDHashOperator
+BlobTableSweepDying(PLDHashTable *table, PLDHashEntryHdr *hdr,
+                    PRUint32 number, void *arg)
+{
+    BlobHashEntry *entry = static_cast<BlobHashEntry*>(hdr);
+    if (entry->mBlob && !NS_GetGC()->GetMark(entry->mBlob))
+        return PL_DHASH_REMOVE;
+
+    return PL_DHASH_NEXT;
+}
+
 ////////////////////////////////////////////////////////////////////////
 // LiteralImpl
 //
@@ -447,10 +506,10 @@ static PLDHashTableOps gBlobTableOps = {
 //   i.e., there is are no resource factories to allow you to generate
 //   customer resources. I doubt that makes sense, anyway.
 //
-class LiteralImpl : public XPCOMGCFinalizedObject, public nsIRDFLiteral {
+class LiteralImpl : public XPCOMGCObject, public nsIRDFLiteral {
 public:
-    static nsresult
-    Create(const PRUnichar* aValue, nsIRDFLiteral** aResult);
+    static LiteralImpl*
+    Create(const PRUnichar* aValue);
 
     // nsISupports
     NS_DECL_ISUPPORTS
@@ -461,6 +520,11 @@ public:
     // nsIRDFLiteral
     NS_DECL_NSIRDFLITERAL
 
+    const PRUnichar* GetValue() const
+    {
+        return mBuffer;
+    }
+
 protected:
     static void* operator new(size_t size, size_t extra)
     {
@@ -468,35 +532,22 @@ protected:
     }
 
     LiteralImpl(const PRUnichar* s, size_t length);
-    virtual ~LiteralImpl();
-
-    const PRUnichar* GetValue() const
-    {
-        return mBuffer;
-    }
 
     PRUnichar mBuffer[1];
 };
 
 
-nsresult
-LiteralImpl::Create(const PRUnichar* aValue, nsIRDFLiteral** aResult)
+LiteralImpl*
+LiteralImpl::Create(const PRUnichar* aValue)
 {
     size_t stringLen = NS_strlen(aValue);
-    *aResult = new(stringLen * sizeof(PRUnichar)) LiteralImpl(aValue, stringLen);
-    return *aResult ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
+    return new(stringLen * sizeof(PRUnichar)) LiteralImpl(aValue, stringLen);
 }
 
 
 LiteralImpl::LiteralImpl(const PRUnichar* s, size_t length)
 {
     nsCharTraits<PRUnichar>::copy(mBuffer, s, length + 1);
-    RDFServiceImpl::gRDFService->RegisterLiteral(this);
-}
-
-LiteralImpl::~LiteralImpl()
-{
-    RDFServiceImpl::gRDFService->UnregisterLiteral(this);
 }
 
 NS_IMPL_THREADSAFE_ADDREF(LiteralImpl)
@@ -562,10 +613,9 @@ LiteralImpl::GetValueConst(const PRUnich
 // DateImpl
 //
 
-class DateImpl : public nsIRDFDate {
+class DateImpl : public XPCOMGCObject, public nsIRDFDate {
 public:
-    DateImpl(const PRTime s);
-    virtual ~DateImpl();
+    DateImpl(const PRTime s) : mValue(s) { }
 
     // nsISupports
     NS_DECL_ISUPPORTS
@@ -581,18 +631,6 @@ private:
     PRTime mValue;
 };
 
-
-DateImpl::DateImpl(const PRTime s)
-    : mValue(s)
-{
-    RDFServiceImpl::gRDFService->RegisterDate(this);
-    NS_ADDREF(RDFServiceImpl::gRDFService);
-}
-
-DateImpl::~DateImpl()
-{
-    RDFServiceImpl::gRDFService->UnregisterDate(this);
-}
 
 NS_IMPL_ADDREF(DateImpl)
 NS_IMPL_RELEASE(DateImpl)
@@ -661,10 +699,9 @@ DateImpl::EqualsDate(nsIRDFDate* date, P
 // IntImpl
 //
 
-class IntImpl : public nsIRDFInt {
+class IntImpl : public XPCOMGCObject, public nsIRDFInt {
 public:
-    IntImpl(PRInt32 s);
-    virtual ~IntImpl();
+    IntImpl(PRInt32 s) : mValue(s) { }
 
     // nsISupports
     NS_DECL_ISUPPORTS
@@ -680,18 +717,6 @@ private:
     PRInt32 mValue;
 };
 
-
-IntImpl::IntImpl(PRInt32 s)
-    : mValue(s)
-{
-    RDFServiceImpl::gRDFService->RegisterInt(this);
-    NS_ADDREF(RDFServiceImpl::gRDFService);
-}
-
-IntImpl::~IntImpl()
-{
-    RDFServiceImpl::gRDFService->UnregisterInt(this);
-}
 
 NS_IMPL_ADDREF(IntImpl)
 NS_IMPL_RELEASE(IntImpl)
@@ -764,7 +789,8 @@ RDFServiceImpl::gRDFService;
 RDFServiceImpl::gRDFService;
 
 RDFServiceImpl::RDFServiceImpl()
-    :  mNamedDataSources(nsnull)
+    : MMgc::GCCallback(NS_GetGC())
+    , mNamedDataSources(nsnull)
 {
     mResources.ops = nsnull;
     mLiterals.ops = nsnull;
@@ -813,9 +839,6 @@ RDFServiceImpl::Init()
         mBlobs.ops = nsnull;
         return NS_ERROR_OUT_OF_MEMORY;
     }
-    mDefaultResourceFactory = do_GetClassObject(kRDFDefaultResourceCID, &rv);
-    NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get default resource factory");
-    if (NS_FAILED(rv)) return rv;
 
 #ifdef PR_LOGGING
     if (! gLog)
@@ -858,7 +881,7 @@ RDFServiceImpl::CreateSingleton(nsISuppo
         return gRDFService->QueryInterface(aIID, aResult);
     }
 
-    nsRefPtr<RDFServiceImpl> serv = new RDFServiceImpl();
+    RDFServiceImpl* serv = new RDFServiceImpl();
     if (!serv)
         return NS_ERROR_OUT_OF_MEMORY;
 
@@ -910,105 +933,24 @@ NS_IMETHODIMP
 NS_IMETHODIMP
 RDFServiceImpl::GetResource(const nsACString& aURI, nsIRDFResource** aResource)
 {
-    // Sanity checks
-    NS_PRECONDITION(aResource != nsnull, "null ptr");
-    NS_PRECONDITION(!aURI.IsEmpty(), "URI is empty");
-    if (! aResource)
-        return NS_ERROR_NULL_POINTER;
-    if (aURI.IsEmpty())
-        return NS_ERROR_INVALID_ARG;
+    NS_ENSURE_ARG(aResource);
 
     const nsAFlatCString& flatURI = PromiseFlatCString(aURI);
     PR_LOG(gLog, PR_LOG_DEBUG, ("rdfserv get-resource %s", flatURI.get()));
 
     // First, check the cache to see if we've already created and
     // registered this thing.
-    PLDHashEntryHdr *hdr =
-        PL_DHashTableOperate(&mResources, flatURI.get(), PL_DHASH_LOOKUP);
+    ResourceHashEntry *entry = static_cast<ResourceHashEntry*>
+        (PL_DHashTableOperate(&mResources, flatURI.get(), PL_DHASH_ADD));
 
-    if (PL_DHASH_ENTRY_IS_BUSY(hdr)) {
-        ResourceHashEntry *entry = static_cast<ResourceHashEntry *>(hdr);
-        NS_ADDREF(*aResource = entry->mResource);
-        return NS_OK;
+
+    if (!entry->mResource) {
+        nsRDFResource *resource = new nsRDFResource(aURI);
+        entry->mResource = resource;
+        entry->mKey = resource->GetInternal();
     }
-
-    // Nope. So go to the repository to create it.
-
-    // Compute the scheme of the URI. Scan forward until we either:
-    //
-    // 1. Reach the end of the string
-    // 2. Encounter a non-alpha character
-    // 3. Encouter a colon.
-    //
-    // If we encounter a colon _before_ encountering a non-alpha
-    // character, then assume it's the scheme.
-    //
-    // XXX Although it's really not correct, we'll allow underscore
-    // characters ('_'), too.
-    nsACString::const_iterator p, end;
-    aURI.BeginReading(p);
-    aURI.EndReading(end);
-    while (p != end && IsLegalSchemeCharacter(*p))
-        ++p;
-
-    nsresult rv;
-    nsCOMPtr<nsIFactory> factory;
-
-    nsACString::const_iterator begin;
-    aURI.BeginReading(begin);
-    if (*p == ':') {
-        // There _was_ a scheme. First see if it's the same scheme
-        // that we just tried to use...
-        if (mLastFactory && mLastURIPrefix.Equals(Substring(begin, p)))
-            factory = mLastFactory;
-        else {
-            // Try to find a factory using the component manager.
-            nsACString::const_iterator begin;
-            aURI.BeginReading(begin);
-            nsCAutoString contractID;
-            contractID = NS_LITERAL_CSTRING(NS_RDF_RESOURCE_FACTORY_CONTRACTID_PREFIX) +
-                         Substring(begin, p);
-
-            factory = do_GetClassObject(contractID.get());
-            if (factory) {
-                // Store the factory in our one-element cache.
-                if (p != begin) {
-                    mLastFactory = factory;
-                    mLastURIPrefix = Substring(begin, p);
-                }
-            }
-        }
-    }
-
-    if (! factory) {
-        // fall through to using the "default" resource factory if either:
-        //
-        // 1. The URI didn't have a scheme, or
-        // 2. There was no resource factory registered for the scheme.
-        factory = mDefaultResourceFactory;
-
-        // Store the factory in our one-element cache.
-        if (p != begin) {
-            mLastFactory = factory;
-            mLastURIPrefix = Substring(begin, p);
-        }
-    }
-
-    nsIRDFResource *result;
-    rv = factory->CreateInstance(nsnull, NS_GET_IID(nsIRDFResource), (void**) &result);
-    if (NS_FAILED(rv)) return rv;
-
-    // Now initialize it with it's URI. At this point, the resource
-    // implementation should register itself with the RDF service.
-    rv = result->Init(flatURI.get());
-    if (NS_FAILED(rv)) {
-        NS_ERROR("unable to initialize resource");
-        NS_RELEASE(result);
-        return rv;
-    }
-
-    *aResource = result; // already refcounted from repository
-    return rv;
+    *aResource = entry->mResource;
+    return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -1093,37 +1035,33 @@ RDFServiceImpl::GetLiteral(const PRUnich
         return NS_ERROR_NULL_POINTER;
 
     // See if we have one already cached
-    PLDHashEntryHdr *hdr =
-        PL_DHashTableOperate(&mLiterals, aValue, PL_DHASH_LOOKUP);
+    LiteralHashEntry *entry = static_cast<LiteralHashEntry*>
+        (PL_DHashTableOperate(&mLiterals, aValue, PL_DHASH_ADD));
 
-    if (PL_DHASH_ENTRY_IS_BUSY(hdr)) {
-        LiteralHashEntry *entry = static_cast<LiteralHashEntry *>(hdr);
-        NS_ADDREF(*aLiteral = entry->mLiteral);
-        return NS_OK;
+    if (!entry->mLiteral) {
+        LiteralImpl *literal = LiteralImpl::Create(aValue);
+        entry->mLiteral = literal;
+        entry->mKey = literal->GetValue();
     }
 
-    // Nope. Create a new one
-    return LiteralImpl::Create(aValue, aLiteral);
+    *aLiteral = entry->mLiteral;
+    return NS_OK;
 }
 
 NS_IMETHODIMP
 RDFServiceImpl::GetDateLiteral(PRTime aTime, nsIRDFDate** aResult)
 {
     // See if we have one already cached
-    PLDHashEntryHdr *hdr =
-        PL_DHashTableOperate(&mDates, &aTime, PL_DHASH_LOOKUP);
+    DateHashEntry *entry = static_cast<DateHashEntry*>
+        (PL_DHashTableOperate(&mDates, &aTime, PL_DHASH_ADD));
 
-    if (PL_DHASH_ENTRY_IS_BUSY(hdr)) {
-        DateHashEntry *entry = static_cast<DateHashEntry *>(hdr);
-        NS_ADDREF(*aResult = entry->mDate);
-        return NS_OK;
+    if (!entry->mDate) {
+        DateImpl* date = new DateImpl(aTime);
+        entry->mDate = date;
+        entry->mKey = aTime;
     }
 
-    DateImpl* result = new DateImpl(aTime);
-    if (! result)
-        return NS_ERROR_OUT_OF_MEMORY;
-
-    NS_ADDREF(*aResult = result);
+    *aResult = entry->mDate;
     return NS_OK;
 }
 
@@ -1131,20 +1069,15 @@ RDFServiceImpl::GetIntLiteral(PRInt32 aI
 RDFServiceImpl::GetIntLiteral(PRInt32 aInt, nsIRDFInt** aResult)
 {
     // See if we have one already cached
-    PLDHashEntryHdr *hdr =
-        PL_DHashTableOperate(&mInts, &aInt, PL_DHASH_LOOKUP);
+    IntHashEntry *entry = static_cast<IntHashEntry*>
+        (PL_DHashTableOperate(&mInts, &aInt, PL_DHASH_ADD));
 
-    if (PL_DHASH_ENTRY_IS_BUSY(hdr)) {
-        IntHashEntry *entry = static_cast<IntHashEntry *>(hdr);
-        NS_ADDREF(*aResult = entry->mInt);
-        return NS_OK;
+    if (!entry->mInt) {
+        entry->mInt = new IntImpl(aInt);
+        entry->mKey = aInt;
     }
 
-    IntImpl* result = new IntImpl(aInt);
-    if (! result)
-        return NS_ERROR_OUT_OF_MEMORY;
-
-    NS_ADDREF(*aResult = result);
+    *aResult = entry->mInt;
     return NS_OK;
 }
 
@@ -1154,20 +1087,14 @@ RDFServiceImpl::GetBlobLiteral(const PRU
 {
     BlobImpl::Data key = { aLength, const_cast<PRUint8 *>(aBytes) };
 
-    PLDHashEntryHdr *hdr =
-        PL_DHashTableOperate(&mBlobs, &key, PL_DHASH_LOOKUP);
+    BlobHashEntry *entry = static_cast<BlobHashEntry*>
+        (PL_DHashTableOperate(&mBlobs, &key, PL_DHASH_ADD));
 
-    if (PL_DHASH_ENTRY_IS_BUSY(hdr)) {
-        BlobHashEntry *entry = static_cast<BlobHashEntry *>(hdr);
-        NS_ADDREF(*aResult = entry->mBlob);
-        return NS_OK;
+    if (!entry->mBlob) {
+        entry->mBlob = new (aLength) BlobImpl(aBytes, aLength);
     }
 
-    BlobImpl *result = new (aLength) BlobImpl(aBytes, aLength);
-    if (! result)
-        return NS_ERROR_OUT_OF_MEMORY;
-
-    NS_ADDREF(*aResult = result);
+    *aResult = entry->mBlob;
     return NS_OK;
 }
 
@@ -1196,93 +1123,6 @@ RDFServiceImpl::IsAnonymousResource(nsIR
         *_result = PR_FALSE;
     }
 
-    return NS_OK;
-}
-
-NS_IMETHODIMP
-RDFServiceImpl::RegisterResource(nsIRDFResource* aResource, PRBool aReplace)
-{
-    NS_PRECONDITION(aResource != nsnull, "null ptr");
-    if (! aResource)
-        return NS_ERROR_NULL_POINTER;
-
-    nsresult rv;
-
-    const char* uri;
-    rv = aResource->GetValueConst(&uri);
-    NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get URI from resource");
-    if (NS_FAILED(rv)) return rv;
-
-    NS_ASSERTION(uri != nsnull, "resource has no URI");
-    if (! uri)
-        return NS_ERROR_NULL_POINTER;
-
-    PLDHashEntryHdr *hdr =
-        PL_DHashTableOperate(&mResources, uri, PL_DHASH_LOOKUP);
-
-    if (PL_DHASH_ENTRY_IS_BUSY(hdr)) {
-        if (!aReplace) {
-            NS_WARNING("resource already registered, and replace not specified");
-            return NS_ERROR_FAILURE;    // already registered
-        }
-
-        // N.B., we do _not_ release the original resource because we
-        // only ever held a weak reference to it. We simply replace
-        // it.
-
-        PR_LOG(gLog, PR_LOG_DEBUG,
-               ("rdfserv   replace-resource [%p] <-- [%p] %s",
-                static_cast<ResourceHashEntry *>(hdr)->mResource,
-                aResource, (const char*) uri));
-    }
-    else {
-        hdr = PL_DHashTableOperate(&mResources, uri, PL_DHASH_ADD);
-        if (! hdr)
-            return NS_ERROR_OUT_OF_MEMORY;
-
-        PR_LOG(gLog, PR_LOG_DEBUG,
-               ("rdfserv   register-resource [%p] %s",
-                aResource, (const char*) uri));
-    }
-
-    // N.B., we only hold a weak reference to the resource: that way,
-    // the resource can be destroyed when the last refcount goes
-    // away. The single addref that the CreateResource() call made
-    // will be owned by the callee.
-    ResourceHashEntry *entry = static_cast<ResourceHashEntry *>(hdr);
-    entry->mResource = aResource;
-    entry->mKey = uri;
-
-    return NS_OK;
-}
-
-NS_IMETHODIMP
-RDFServiceImpl::UnregisterResource(nsIRDFResource* aResource)
-{
-    NS_PRECONDITION(aResource != nsnull, "null ptr");
-    if (! aResource)
-        return NS_ERROR_NULL_POINTER;
-
-    nsresult rv;
-
-    const char* uri;
-    rv = aResource->GetValueConst(&uri);
-    if (NS_FAILED(rv)) return rv;
-
-    NS_ASSERTION(uri != nsnull, "resource has no URI");
-    if (! uri)
-        return NS_ERROR_UNEXPECTED;
-
-    PR_LOG(gLog, PR_LOG_DEBUG,
-           ("rdfserv unregister-resource [%p] %s",
-            aResource, (const char*) uri));
-
-#ifdef DEBUG
-    if (PL_DHASH_ENTRY_IS_FREE(PL_DHashTableOperate(&mResources, uri, PL_DHASH_LOOKUP)))
-        NS_WARNING("resource was never registered");
-#endif
-
-    PL_DHashTableOperate(&mResources, uri, PL_DHASH_REMOVE);
     return NS_OK;
 }
 
@@ -1334,42 +1174,6 @@ RDFServiceImpl::RegisterDataSource(nsIRD
 }
 
 NS_IMETHODIMP
-RDFServiceImpl::UnregisterDataSource(nsIRDFDataSource* aDataSource)
-{
-    NS_PRECONDITION(aDataSource != nsnull, "null ptr");
-    if (! aDataSource)
-        return NS_ERROR_NULL_POINTER;
-
-    nsresult rv;
-
-    nsXPIDLCString uri;
-    rv = aDataSource->GetURI(getter_Copies(uri));
-    if (NS_FAILED(rv)) return rv;
-
-    //NS_ASSERTION(uri != nsnull, "datasource has no URI");
-    if (! uri)
-        return NS_ERROR_UNEXPECTED;
-
-    PLHashEntry** hep =
-        PL_HashTableRawLookup(mNamedDataSources, (*mNamedDataSources->keyHash)(uri), uri);
-
-    // It may well be that this datasource was never registered. If
-    // so, don't unregister it.
-    if (! *hep || ((*hep)->value != aDataSource))
-        return NS_OK;
-
-    // N.B., we only held a weak reference to the datasource, so we
-    // don't release here.
-    PL_HashTableRawRemove(mNamedDataSources, hep, *hep);
-
-    PR_LOG(gLog, PR_LOG_NOTICE,
-           ("rdfserv unregister-datasource [%p] %s",
-            aDataSource, (const char*) uri));
-
-    return NS_OK;
-}
-
-NS_IMETHODIMP
 RDFServiceImpl::GetDataSource(const char* aURI, nsIRDFDataSource** aDataSource)
 {
     // Use the other GetDataSource and ask for a non-blocking Refresh.
@@ -1400,8 +1204,8 @@ RDFServiceImpl::GetDataSource(const char
     nsCAutoString spec(aURI);
 
     if (!StringBeginsWith(spec, NS_LITERAL_CSTRING("rdf:"))) {
-        nsCOMPtr<nsIURI> uri;
-        NS_NewURI(getter_AddRefs(uri), spec);
+        nsIURI* uri = nsnull;
+        NS_NewURI(&uri, spec);
         if (uri)
             uri->GetSpec(spec);
     }
@@ -1413,14 +1217,13 @@ RDFServiceImpl::GetDataSource(const char
             static_cast<nsIRDFDataSource*>(PL_HashTableLookup(mNamedDataSources, spec.get()));
 
         if (cached) {
-            NS_ADDREF(cached);
             *aDataSource = cached;
             return NS_OK;
         }
     }
 
     // Nope. So go to the repository to try to create it.
-    nsCOMPtr<nsIRDFDataSource> ds;
+    nsIRDFDataSource* ds = nsnull;
     if (StringBeginsWith(spec, NS_LITERAL_CSTRING("rdf:"))) {
         // It's a built-in data source. Convert it to a contract ID.
         nsCAutoString contractID(
@@ -1435,7 +1238,7 @@ RDFServiceImpl::GetDataSource(const char
         ds = do_GetService(contractID.get(), &rv);
         if (NS_FAILED(rv)) return rv;
 
-        nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(ds);
+        nsIRDFRemoteDataSource* remote = do_QueryInterface(ds);
         if (remote) {
             rv = remote->Init(spec.get());
             if (NS_FAILED(rv)) return rv;
@@ -1446,7 +1249,7 @@ RDFServiceImpl::GetDataSource(const char
         ds = do_CreateInstance(kRDFXMLDataSourceCID, &rv);
         if (NS_FAILED(rv)) return rv;
 
-        nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(ds));
+        nsIRDFRemoteDataSource* remote(do_QueryInterface(ds));
         NS_ASSERTION(remote, "not a remote RDF/XML data source!");
         if (! remote) return NS_ERROR_UNEXPECTED;
 
@@ -1458,228 +1261,17 @@ RDFServiceImpl::GetDataSource(const char
     }
 
     *aDataSource = ds;
-    NS_ADDREF(*aDataSource);
     return NS_OK;
 }
 
-////////////////////////////////////////////////////////////////////////
-
-nsresult
-RDFServiceImpl::RegisterLiteral(nsIRDFLiteral* aLiteral)
+void
+RDFServiceImpl::presweep()
 {
-    const PRUnichar* value;
-    aLiteral->GetValueConst(&value);
-
-    NS_ASSERTION(PL_DHASH_ENTRY_IS_FREE(PL_DHashTableOperate(&mLiterals,
-                                                             value,
-                                                             PL_DHASH_LOOKUP)),
-                 "literal already registered");
-
-    PLDHashEntryHdr *hdr =
-        PL_DHashTableOperate(&mLiterals, value, PL_DHASH_ADD);
-
-    if (! hdr)
-        return NS_ERROR_OUT_OF_MEMORY;
-
-    LiteralHashEntry *entry = static_cast<LiteralHashEntry *>(hdr);
-
-    // N.B., we only hold a weak reference to the literal: that
-    // way, the literal can be destroyed when the last refcount
-    // goes away. The single addref that the CreateLiteral() call
-    // made will be owned by the callee.
-    entry->mLiteral = aLiteral;
-    entry->mKey = value;
-
-    PR_LOG(gLog, PR_LOG_DEBUG,
-           ("rdfserv   register-literal [%p] %s",
-            aLiteral, (const PRUnichar*) value));
-
-    return NS_OK;
+    PL_HashTableEnumerateEntries(mNamedDataSources, DataSourceSweepDying,
+                                 nsnull);
+    PL_DHashTableEnumerate(&mResources, ResourceTableSweepDying, nsnull);
+    PL_DHashTableEnumerate(&mLiterals, LiteralTableSweepDying, nsnull);
+    PL_DHashTableEnumerate(&mInts, IntTableSweepDying, nsnull);
+    PL_DHashTableEnumerate(&mDates, DateTableSweepDying, nsnull);
+    PL_DHashTableEnumerate(&mBlobs, BlobTableSweepDying, nsnull);
 }
-
-
-nsresult
-RDFServiceImpl::UnregisterLiteral(nsIRDFLiteral* aLiteral)
-{
-    const PRUnichar* value;
-    aLiteral->GetValueConst(&value);
-
-    NS_ASSERTION(PL_DHASH_ENTRY_IS_BUSY(PL_DHashTableOperate(&mLiterals,
-                                                             value,
-                                                             PL_DHASH_LOOKUP)),
-                 "literal was never registered");
-
-    PL_DHashTableOperate(&mLiterals, value, PL_DHASH_REMOVE);
-
-    // N.B. that we _don't_ release the literal: we only held a weak
-    // reference to it in the hashtable.
-    PR_LOG(gLog, PR_LOG_DEBUG,
-           ("rdfserv unregister-literal [%p] %s",
-            aLiteral, (const PRUnichar*) value));
-
-    return NS_OK;
-}
-
-//----------------------------------------------------------------------
-
-nsresult
-RDFServiceImpl::RegisterInt(nsIRDFInt* aInt)
-{
-    PRInt32 value;
-    aInt->GetValue(&value);
-
-    NS_ASSERTION(PL_DHASH_ENTRY_IS_FREE(PL_DHashTableOperate(&mInts,
-                                                             &value,
-                                                             PL_DHASH_LOOKUP)),
-                 "int already registered");
-
-    PLDHashEntryHdr *hdr =
-        PL_DHashTableOperate(&mInts, &value, PL_DHASH_ADD);
-
-    if (! hdr)
-        return NS_ERROR_OUT_OF_MEMORY;
-
-    IntHashEntry *entry = static_cast<IntHashEntry *>(hdr);
-
-    // N.B., we only hold a weak reference to the literal: that
-    // way, the literal can be destroyed when the last refcount
-    // goes away. The single addref that the CreateInt() call
-    // made will be owned by the callee.
-    entry->mInt = aInt;
-    entry->mKey = value;
-
-    PR_LOG(gLog, PR_LOG_DEBUG,
-           ("rdfserv   register-int [%p] %d",
-            aInt, value));
-
-    return NS_OK;
-}
-
-
-nsresult
-RDFServiceImpl::UnregisterInt(nsIRDFInt* aInt)
-{
-    PRInt32 value;
-    aInt->GetValue(&value);
-
-    NS_ASSERTION(PL_DHASH_ENTRY_IS_BUSY(PL_DHashTableOperate(&mInts,
-                                                             &value,
-                                                             PL_DHASH_LOOKUP)),
-                 "int was never registered");
-
-    PL_DHashTableOperate(&mInts, &value, PL_DHASH_REMOVE);
-
-    // N.B. that we _don't_ release the literal: we only held a weak
-    // reference to it in the hashtable.
-    PR_LOG(gLog, PR_LOG_DEBUG,
-           ("rdfserv unregister-int [%p] %d",
-            aInt, value));
-
-    return NS_OK;
-}
-
-//----------------------------------------------------------------------
-
-nsresult
-RDFServiceImpl::RegisterDate(nsIRDFDate* aDate)
-{
-    PRTime value;
-    aDate->GetValue(&value);
-
-    NS_ASSERTION(PL_DHASH_ENTRY_IS_FREE(PL_DHashTableOperate(&mDates,
-                                                             &value,
-                                                             PL_DHASH_LOOKUP)),
-                 "date already registered");
-
-    PLDHashEntryHdr *hdr =
-        PL_DHashTableOperate(&mDates, &value, PL_DHASH_ADD);
-
-    if (! hdr)
-        return NS_ERROR_OUT_OF_MEMORY;
-
-    DateHashEntry *entry = static_cast<DateHashEntry *>(hdr);
-
-    // N.B., we only hold a weak reference to the literal: that
-    // way, the literal can be destroyed when the last refcount
-    // goes away. The single addref that the CreateDate() call
-    // made will be owned by the callee.
-    entry->mDate = aDate;
-    entry->mKey = value;
-
-    PR_LOG(gLog, PR_LOG_DEBUG,
-           ("rdfserv   register-date [%p] %ld",
-            aDate, value));
-
-    return NS_OK;
-}
-
-
-nsresult
-RDFServiceImpl::UnregisterDate(nsIRDFDate* aDate)
-{
-    PRTime value;
-    aDate->GetValue(&value);
-
-    NS_ASSERTION(PL_DHASH_ENTRY_IS_BUSY(PL_DHashTableOperate(&mDates,
-                                                             &value,
-                                                             PL_DHASH_LOOKUP)),
-                 "date was never registered");
-
-    PL_DHashTableOperate(&mDates, &value, PL_DHASH_REMOVE);
-
-    // N.B. that we _don't_ release the literal: we only held a weak
-    // reference to it in the hashtable.
-    PR_LOG(gLog, PR_LOG_DEBUG,
-           ("rdfserv unregister-date [%p] %ld",
-            aDate, value));
-
-    return NS_OK;
-}
-
-nsresult
-RDFServiceImpl::RegisterBlob(BlobImpl *aBlob)
-{
-    NS_ASSERTION(PL_DHASH_ENTRY_IS_FREE(PL_DHashTableOperate(&mBlobs,
-                                                             &aBlob->mData,
-                                                             PL_DHASH_LOOKUP)),
-                 "blob already registered");
-
-    PLDHashEntryHdr *hdr = 
-        PL_DHashTableOperate(&mBlobs, &aBlob->mData, PL_DHASH_ADD);
-
-    if (! hdr)
-        return NS_ERROR_OUT_OF_MEMORY;
-
-    BlobHashEntry *entry = static_cast<BlobHashEntry *>(hdr);
-
-    // N.B., we only hold a weak reference to the literal: that
-    // way, the literal can be destroyed when the last refcount
-    // goes away. The single addref that the CreateInt() call
-    // made will be owned by the callee.
-    entry->mBlob = aBlob;
-
-    PR_LOG(gLog, PR_LOG_DEBUG,
-           ("rdfserv   register-blob [%p] %s",
-            aBlob, aBlob->mData.mBytes));
-
-    return NS_OK;
-}
-
-nsresult
-RDFServiceImpl::UnregisterBlob(BlobImpl *aBlob)
-{
-    NS_ASSERTION(PL_DHASH_ENTRY_IS_BUSY(PL_DHashTableOperate(&mBlobs,
-                                                             &aBlob->mData,
-                                                             PL_DHASH_LOOKUP)),
-                 "blob was never registered");
-
-    PL_DHashTableOperate(&mBlobs, &aBlob->mData, PL_DHASH_REMOVE);
- 
-     // N.B. that we _don't_ release the literal: we only held a weak
-     // reference to it in the hashtable.
-    PR_LOG(gLog, PR_LOG_DEBUG,
-           ("rdfserv unregister-blob [%p] %s",
-            aBlob, aBlob->mData.mBytes));
-
-    return NS_OK;
-}
diff --git a/rdf/base/src/nsRDFService.h b/rdf/base/src/nsRDFService.h
--- a/rdf/base/src/nsRDFService.h
+++ b/rdf/base/src/nsRDFService.h
@@ -66,8 +66,10 @@ class nsIRDFDate;
 class nsIRDFDate;
 class BlobImpl;
 
-class RDFServiceImpl : public nsIRDFService,
-                       public nsSupportsWeakReference
+class RDFServiceImpl : public XPCOMGCFinalizedObject,
+                       public nsIRDFService,
+                       public nsSupportsWeakReference,
+                       public MMgc::GCCallback
 {
 protected:
     PLHashTable* mNamedDataSources;
@@ -77,13 +79,11 @@ protected:
     PLDHashTable mDates;
     PLDHashTable mBlobs;
 
-    nsCAutoString mLastURIPrefix;
-    nsCOMPtr<nsIFactory> mLastFactory;
-    nsCOMPtr<nsIFactory> mDefaultResourceFactory;
-
     RDFServiceImpl();
     nsresult Init();
     virtual ~RDFServiceImpl();
+
+    virtual void presweep();
 
 public:
     static RDFServiceImpl *gRDFService NS_VISIBILITY_HIDDEN;
@@ -96,16 +96,6 @@ public:
     // nsIRDFService
     NS_DECL_NSIRDFSERVICE
 
-    // Implementation methods
-    nsresult RegisterLiteral(nsIRDFLiteral* aLiteral);
-    nsresult UnregisterLiteral(nsIRDFLiteral* aLiteral);
-    nsresult RegisterInt(nsIRDFInt* aInt);
-    nsresult UnregisterInt(nsIRDFInt* aInt);
-    nsresult RegisterDate(nsIRDFDate* aDate);
-    nsresult UnregisterDate(nsIRDFDate* aDate);
-    nsresult RegisterBlob(BlobImpl* aBlob);
-    nsresult UnregisterBlob(BlobImpl* aBlob);
-
     nsresult GetDataSource(const char *aURI, PRBool aBlock, nsIRDFDataSource **aDataSource );
 };
 
diff --git a/rdf/base/src/nsRDFXMLDataSource.cpp b/rdf/base/src/nsRDFXMLDataSource.cpp
--- a/rdf/base/src/nsRDFXMLDataSource.cpp
+++ b/rdf/base/src/nsRDFXMLDataSource.cpp
@@ -123,6 +123,7 @@
 #include "nsNameSpaceMap.h"
 #include "nsCRT.h"
 #include "nsCycleCollectionParticipant.h"
+#include "nsRDFService.h"
 
 #include "rdfIDataSource.h"
 
@@ -140,7 +141,8 @@ static PRLogModuleInfo* gLog;
 // RDFXMLDataSourceImpl
 //
 
-class RDFXMLDataSourceImpl : public nsIRDFDataSource,
+class RDFXMLDataSourceImpl : public XPCOMGCFinalizedObject,
+                             public nsIRDFDataSource,
                              public nsIRDFRemoteDataSource,
                              public nsIRDFXMLSink,
                              public nsIRDFXMLSource,
@@ -163,10 +165,6 @@ protected:
     nsCOMPtr<nsIURI>    mURL;
     nsCOMPtr<nsIStreamListener> mListener;
     nsNameSpaceMap      mNameSpaces;
-
-    // pseudo-constants
-    static PRInt32 gRefCnt;
-    static nsIRDFService* gRDFService;
 
     nsresult Init();
     RDFXMLDataSourceImpl(void);
@@ -321,14 +319,14 @@ public:
     // rdfIDataSource
     NS_IMETHOD VisitAllSubjects(rdfITripleVisitor *aVisitor) {
         nsresult rv;
-        nsCOMPtr<rdfIDataSource> rdfds = do_QueryInterface(mInner, &rv);
+        rdfIDataSource* rdfds = do_QueryInterface(mInner, &rv);
         if (NS_FAILED(rv)) return rv;
         return rdfds->VisitAllSubjects(aVisitor);
     } 
 
     NS_IMETHOD VisitAllTriples(rdfITripleVisitor *aVisitor) {
         nsresult rv;
-        nsCOMPtr<rdfIDataSource> rdfds = do_QueryInterface(mInner, &rv);
+        rdfIDataSource* rdfds = do_QueryInterface(mInner, &rv);
         if (NS_FAILED(rv)) return rv;
         return rdfds->VisitAllTriples(aVisitor);
     } 
@@ -381,9 +379,6 @@ protected:
     BlockingParse(nsIURI* aURL, nsIStreamListener* aConsumer);
 };
 
-PRInt32         RDFXMLDataSourceImpl::gRefCnt = 0;
-nsIRDFService*  RDFXMLDataSourceImpl::gRDFService;
-
 static const char kFileURIPrefix[] = "file:";
 static const char kResourceURIPrefix[] = "resource:";
 
@@ -409,7 +404,6 @@ NS_NewRDFXMLDataSource(nsIRDFDataSource*
         return rv;
     }
 
-    NS_ADDREF(datasource);
     *aResult = datasource;
     return NS_OK;
 }
@@ -434,13 +428,6 @@ RDFXMLDataSourceImpl::Init()
     mInner = do_CreateInstance(kRDFInMemoryDataSourceCID, &rv);
     if (NS_FAILED(rv)) return rv;
 
-    if (gRefCnt++ == 0) {
-        rv = CallGetService(kRDFServiceCID, &gRDFService);
-
-        NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service");
-        if (NS_FAILED(rv)) return rv;
-    }
-
     return NS_OK;
 }
 
@@ -448,18 +435,12 @@ RDFXMLDataSourceImpl::~RDFXMLDataSourceI
 RDFXMLDataSourceImpl::~RDFXMLDataSourceImpl(void)
 {
     nsresult rv;
-
-    // Unregister first so that nobody else tries to get us.
-    rv = gRDFService->UnregisterDataSource(this);
 
     // Now flush contents
     rv = Flush();
 
     // Release RDF/XML sink observers
     mObservers.Clear();
-
-    if (--gRefCnt == 0)
-        NS_IF_RELEASE(gRDFService);
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(RDFXMLDataSourceImpl)
@@ -494,15 +475,15 @@ RDFXMLDataSourceImpl::BlockingParse(nsIU
     // to the parser: it seems like this is something that netlib
     // should be able to do by itself.
     
-    nsCOMPtr<nsIChannel> channel;
-    nsCOMPtr<nsIRequest> request;
+    nsIChannel* channel = nsnull;
+    nsIRequest* request = nsnull;
 
     // Null LoadGroup ?
-    rv = NS_NewChannel(getter_AddRefs(channel), aURL, nsnull);
+    rv = NS_NewChannel(&channel, aURL, nsnull);
     if (NS_FAILED(rv)) return rv;
-    nsCOMPtr<nsIInputStream> in;
+    nsIInputStream* in = nsnull;
     PRUint32 sourceOffset = 0;
-    rv = channel->Open(getter_AddRefs(in));
+    rv = channel->Open(&in);
 
     // Report success if the file doesn't exist, but propagate other errors.
     if (rv == NS_ERROR_FILE_NOT_FOUND) return NS_OK;
@@ -515,8 +496,8 @@ RDFXMLDataSourceImpl::BlockingParse(nsIU
 
     // Wrap the channel's input stream in a buffered stream to ensure that
     // ReadSegments is implemented (which OnDataAvailable expects).
-    nsCOMPtr<nsIInputStream> bufStream;
-    rv = NS_NewBufferedInputStream(getter_AddRefs(bufStream), in,
+    nsIInputStream* bufStream = nsnull;
+    rv = NS_NewBufferedInputStream(&bufStream, in,
                                    4096 /* buffer size */);
     if (NS_FAILED(rv)) return rv;
 
@@ -526,7 +507,7 @@ RDFXMLDataSourceImpl::BlockingParse(nsIU
         // Make sure to hold a strong reference to the observer so
         // that it doesn't go away in this call if it removes itself
         // as an observer
-        nsCOMPtr<nsIRDFXMLSinkObserver> obs = mObservers[i];
+        nsIRDFXMLSinkObserver* obs = mObservers[i];
 
         if (obs) {
             obs->OnBeginLoad(this);
@@ -565,7 +546,7 @@ RDFXMLDataSourceImpl::BlockingParse(nsIU
         // Make sure to hold a strong reference to the observer so
         // that it doesn't go away in this call if it removes itself
         // as an observer
-        nsCOMPtr<nsIRDFXMLSinkObserver> obs = mObservers[i];
+        nsIRDFXMLSinkObserver* obs = mObservers[i];
 
         if (obs) {
             if (NS_FAILED(rv))
@@ -604,7 +585,7 @@ RDFXMLDataSourceImpl::Init(const char* u
         mIsWritable = PR_FALSE;
     }
 
-    rv = gRDFService->RegisterDataSource(this, PR_FALSE);
+    rv = RDFServiceImpl::gRDFService->RegisterDataSource(this, PR_FALSE);
     if (NS_FAILED(rv)) return rv;
 
     return NS_OK;
@@ -642,7 +623,7 @@ RDFXMLDataSourceImpl::Assert(nsIRDFResou
     if (IsLoading()) {
         PRBool hasAssertion = PR_FALSE;
 
-        nsCOMPtr<nsIRDFPurgeableDataSource> gcable = do_QueryInterface(mInner);
+        nsIRDFPurgeableDataSource* gcable = do_QueryInterface(mInner);
         if (gcable) {
             rv = gcable->Mark(aSource, aProperty, aTarget, aTruthValue, &hasAssertion);
             if (NS_FAILED(rv)) return rv;
@@ -754,7 +735,7 @@ RDFXMLDataSourceImpl::rdfXMLFlush(nsIURI
         // we are, we're screwed: it's too late to serialize because
         // many of the services that we'll need to acquire to properly
         // write the file will be unaquirable.
-        nsCOMPtr<nsIRDFService> dummy = do_GetService(kRDFServiceCID, &rv);
+        nsIRDFService* dummy = do_GetService(kRDFServiceCID, &rv);
         if (NS_FAILED(rv)) {
             NS_WARNING("unable to Flush() diry datasource during XPCOM shutdown");
             return rv;
@@ -763,24 +744,24 @@ RDFXMLDataSourceImpl::rdfXMLFlush(nsIURI
 
     // Is it a file? If so, we can write to it. Some day, it'd be nice
     // if we didn't care what kind of stream this was...
-    nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(aURI);
+    nsIFileURL* fileURL = do_QueryInterface(aURI);
     
     if (fileURL) {
-        nsCOMPtr<nsIFile> file;
-        fileURL->GetFile(getter_AddRefs(file));
+        nsIFile* file = nsnull;
+        fileURL->GetFile(&file);
         if (file) {
             // get a safe output stream, so we don't clobber the datasource file unless
             // all the writes succeeded.
-            nsCOMPtr<nsIOutputStream> out;
-            rv = NS_NewSafeLocalFileOutputStream(getter_AddRefs(out),
+            nsIOutputStream* out = nsnull;
+            rv = NS_NewSafeLocalFileOutputStream(&out,
                                                  file,
                                                  PR_WRONLY | PR_CREATE_FILE,
                                                  /*octal*/ 0666,
                                                  0);
             if (NS_FAILED(rv)) return rv;
 
-            nsCOMPtr<nsIOutputStream> bufferedOut;
-            rv = NS_NewBufferedOutputStream(getter_AddRefs(bufferedOut), out, 4096);
+            nsIOutputStream* bufferedOut = nsnull;
+            rv = NS_NewBufferedOutputStream(&bufferedOut, out, 4096);
             if (NS_FAILED(rv)) return rv;
 
             rv = Serialize(bufferedOut);
@@ -788,7 +769,7 @@ RDFXMLDataSourceImpl::rdfXMLFlush(nsIURI
             
             // All went ok. Maybe except for problems in Write(), but the stream detects
             // that for us
-            nsCOMPtr<nsISafeOutputStream> safeStream = do_QueryInterface(bufferedOut, &rv);
+            nsISafeOutputStream* safeStream = do_QueryInterface(bufferedOut, &rv);
             if (NS_FAILED(rv)) return rv;
 
             rv = safeStream->Finish();
@@ -818,8 +799,8 @@ RDFXMLDataSourceImpl::FlushTo(const char
         return NS_ERROR_ILLEGAL_VALUE;
     }
 
-    nsCOMPtr<nsIURI>  url;
-    nsresult rv = NS_NewURI(getter_AddRefs(url), aURI);
+    nsIURI*  url = nsnull;
+    nsresult rv = NS_NewURI(&url, aURI);
     if (NS_FAILED(rv))
       return rv;
     rv = rdfXMLFlush(url);
@@ -907,7 +888,7 @@ RDFXMLDataSourceImpl::Refresh(PRBool aBl
 
     if (! mURL)
         return NS_ERROR_FAILURE;
-    nsCOMPtr<nsIRDFXMLParser> parser = do_CreateInstance("@mozilla.org/rdf/xml-parser;1");
+    nsIRDFXMLParser* parser = do_CreateInstance("@mozilla.org/rdf/xml-parser;1");
     if (! parser)
         return NS_ERROR_FAILURE;
 
@@ -953,7 +934,7 @@ RDFXMLDataSourceImpl::BeginLoad(void)
         // Make sure to hold a strong reference to the observer so
         // that it doesn't go away in this call if it removes itself
         // as an observer
-        nsCOMPtr<nsIRDFXMLSinkObserver> obs = mObservers[i];
+        nsIRDFXMLSinkObserver* obs = mObservers[i];
 
         if (obs) {
             obs->OnBeginLoad(this);
@@ -978,7 +959,7 @@ RDFXMLDataSourceImpl::Interrupt(void)
         // Make sure to hold a strong reference to the observer so
         // that it doesn't go away in this call if it removes itself
         // as an observer
-        nsCOMPtr<nsIRDFXMLSinkObserver> obs = mObservers[i];
+        nsIRDFXMLSinkObserver* obs = mObservers[i];
 
         if (obs) {
             obs->OnInterrupt(this);
@@ -1003,7 +984,7 @@ RDFXMLDataSourceImpl::Resume(void)
         // Make sure to hold a strong reference to the observer so
         // that it doesn't go away in this call if it removes itself
         // as an observer
-        nsCOMPtr<nsIRDFXMLSinkObserver> obs = mObservers[i];
+        nsIRDFXMLSinkObserver* obs = mObservers[i];
 
         if (obs) {
             obs->OnResume(this);
@@ -1027,7 +1008,7 @@ RDFXMLDataSourceImpl::EndLoad(void)
     mLoadState = eLoadState_Loaded;
 
     // Clear out any unmarked assertions from the datasource.
-    nsCOMPtr<nsIRDFPurgeableDataSource> gcable = do_QueryInterface(mInner);
+    nsIRDFPurgeableDataSource* gcable = do_QueryInterface(mInner);
     if (gcable) {
         gcable->Sweep();
     }
@@ -1037,7 +1018,7 @@ RDFXMLDataSourceImpl::EndLoad(void)
         // Make sure to hold a strong reference to the observer so
         // that it doesn't go away in this call if it removes itself
         // as an observer
-        nsCOMPtr<nsIRDFXMLSinkObserver> obs = mObservers[i];
+        nsIRDFXMLSinkObserver* obs = mObservers[i];
 
         if (obs) {
             obs->OnEndLoad(this);
@@ -1097,7 +1078,7 @@ RDFXMLDataSourceImpl::OnStopRequest(nsIR
             // Make sure to hold a strong reference to the observer so
             // that it doesn't go away in this call if it removes
             // itself as an observer
-            nsCOMPtr<nsIRDFXMLSinkObserver> obs = mObservers[i];
+            nsIRDFXMLSinkObserver* obs = mObservers[i];
 
             if (obs) {
                 obs->OnError(this, status, nsnull);
@@ -1137,7 +1118,7 @@ RDFXMLDataSourceImpl::Serialize(nsIOutpu
 RDFXMLDataSourceImpl::Serialize(nsIOutputStream* aStream)
 {
     nsresult rv;
-    nsCOMPtr<nsIRDFXMLSerializer> serializer
+    nsIRDFXMLSerializer* serializer
         = do_CreateInstance("@mozilla.org/rdf/xml-serializer;1", &rv);
 
     if (! serializer)
@@ -1158,7 +1139,7 @@ RDFXMLDataSourceImpl::Serialize(nsIOutpu
     }
 
     // Serialize!
-    nsCOMPtr<nsIRDFXMLSource> source = do_QueryInterface(serializer);
+    nsIRDFXMLSource* source = do_QueryInterface(serializer);
     if (! source)
         return NS_ERROR_FAILURE;
 
diff --git a/rdf/build/nsRDFModule.cpp b/rdf/build/nsRDFModule.cpp
--- a/rdf/build/nsRDFModule.cpp
+++ b/rdf/build/nsRDFModule.cpp
@@ -90,9 +90,6 @@ CreateNew##_func(nsISupports* aOuter, RE
     return rv;                                                       \
 }
 
-extern nsresult
-NS_NewDefaultResource(nsIRDFResource** aResult);
-
 MAKE_CTOR(RDFXMLDataSource,RDFXMLDataSource,RDFDataSource)
 MAKE_CTOR(RDFCompositeDataSource,RDFCompositeDataSource,RDFCompositeDataSource)
 MAKE_CTOR(RDFContainer,RDFContainer,RDFContainer)
@@ -100,7 +97,6 @@ MAKE_CTOR(RDFContainerUtils,RDFContainer
 MAKE_CTOR(RDFContainerUtils,RDFContainerUtils,RDFContainerUtils)
 
 MAKE_CTOR(RDFContentSink,RDFContentSink,RDFContentSink)
-MAKE_CTOR(RDFDefaultResource,DefaultResource,RDFResource)
 
 #define MAKE_RDF_CTOR(_func,_new,_ifname)                            \
 static NS_IMETHODIMP                                                 \
@@ -159,14 +155,6 @@ static const nsModuleComponentInfo compo
       NS_RDFXMLDATASOURCE_CID,
       NS_RDF_DATASOURCE_CONTRACTID_PREFIX "xml-datasource", 
       CreateNewRDFXMLDataSource
-    },
-
-    // register our built-in resource factories:
-    { "RDF Default Resource Factory", 
-      NS_RDFDEFAULTRESOURCE_CID,
-      // Note: default resource factory has no name= part
-      NS_RDF_RESOURCE_FACTORY_CONTRACTID, 
-      CreateNewRDFDefaultResource
     },
 
     // register all the other rdf components:
diff --git a/rdf/datasource/src/nsLocalStore.cpp b/rdf/datasource/src/nsLocalStore.cpp
--- a/rdf/datasource/src/nsLocalStore.cpp
+++ b/rdf/datasource/src/nsLocalStore.cpp
@@ -70,7 +70,8 @@
 
 ////////////////////////////////////////////////////////////////////////
 
-class LocalStoreImpl : public nsILocalStore,
+class LocalStoreImpl : public XPCOMGCFinalizedObject,
+                       public nsILocalStore,
                        public nsIRDFDataSource,
                        public nsIRDFRemoteDataSource,
                        public nsIObserver,
@@ -233,8 +234,6 @@ LocalStoreImpl::LocalStoreImpl(void)
 
 LocalStoreImpl::~LocalStoreImpl(void)
 {
-    if (mRDFService)
-        mRDFService->UnregisterDataSource(this);
 }
 
 
@@ -253,7 +252,6 @@ NS_NewLocalStore(nsISupports* aOuter, RE
     if (! impl)
         return NS_ERROR_OUT_OF_MEMORY;
 
-    NS_ADDREF(impl);
 
     nsresult rv;
     rv = impl->Init();
@@ -286,7 +284,7 @@ NS_IMETHODIMP
 NS_IMETHODIMP
 LocalStoreImpl::GetLoaded(PRBool* _result)
 {
-	nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(mInner);
+	nsIRDFRemoteDataSource* remote = do_QueryInterface(mInner);
     NS_ASSERTION(remote != nsnull, "not an nsIRDFRemoteDataSource");
 	if (! remote)
         return NS_ERROR_UNEXPECTED;
@@ -304,7 +302,7 @@ NS_IMETHODIMP
 NS_IMETHODIMP
 LocalStoreImpl::Flush()
 {
-	nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(mInner);
+	nsIRDFRemoteDataSource* remote = do_QueryInterface(mInner);
     // FIXME Bug 340242: Temporarily make this a warning rather than an
     // assertion until we sort out the ordering of how we write
     // everything to the localstore, flush it, and disconnect it when
@@ -326,7 +324,7 @@ NS_IMETHODIMP
 NS_IMETHODIMP
 LocalStoreImpl::Refresh(PRBool sync)
 {
-	nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(mInner);
+	nsIRDFRemoteDataSource* remote = do_QueryInterface(mInner);
     NS_ASSERTION(remote != nsnull, "not an nsIRDFRemoteDataSource");
 	if (! remote)
         return NS_ERROR_UNEXPECTED;
@@ -349,7 +347,7 @@ LocalStoreImpl::Init()
     mRDFService->RegisterDataSource(this, PR_FALSE);
 
     // Register as an observer of profile changes
-    nsCOMPtr<nsIObserverService> obs =
+    nsIObserverService* obs =
         do_GetService("@mozilla.org/observer-service;1");
 
     if (obs) {
@@ -368,8 +366,8 @@ LocalStoreImpl::CreateLocalStore(nsIFile
     rv = aFile->Create(nsIFile::NORMAL_FILE_TYPE, 0666);
     if (NS_FAILED(rv)) return rv;
 
-    nsCOMPtr<nsIOutputStream> outStream;
-    rv = NS_NewLocalFileOutputStream(getter_AddRefs(outStream), aFile);
+    nsIOutputStream* outStream = nsnull;
+    rv = NS_NewLocalFileOutputStream(&outStream, aFile);
     if (NS_FAILED(rv)) return rv;
 
     const char defaultRDF[] = 
@@ -405,8 +403,8 @@ LocalStoreImpl::LoadData()
     // Look for localstore.rdf in the current profile
     // directory. Bomb if we can't find it.
 
-    nsCOMPtr<nsIFile> aFile;
-    rv = NS_GetSpecialDirectory(NS_APP_LOCALSTORE_50_FILE, getter_AddRefs(aFile));
+    nsIFile* aFile = nsnull;
+    rv = NS_GetSpecialDirectory(NS_APP_LOCALSTORE_50_FILE, &aFile);
     if (NS_FAILED(rv)) return rv;
 
     PRBool fileExistsFlag = PR_FALSE;
@@ -420,11 +418,11 @@ LocalStoreImpl::LoadData()
     mInner = do_CreateInstance(NS_RDF_DATASOURCE_CONTRACTID_PREFIX "xml-datasource", &rv);
     if (NS_FAILED(rv)) return rv;
 
-    nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(mInner, &rv);
+    nsIRDFRemoteDataSource* remote = do_QueryInterface(mInner, &rv);
     if (NS_FAILED(rv)) return rv;
 
-    nsCOMPtr<nsIURI> aURI;
-    rv = NS_NewFileURI(getter_AddRefs(aURI), aFile);
+    nsIURI* aURI = nsnull;
+    rv = NS_NewFileURI(&aURI, aFile);
     if (NS_FAILED(rv)) return rv;
 
     nsCAutoString spec;
@@ -499,7 +497,7 @@ LocalStoreImpl::Observe(nsISupports *aSu
     if (!nsCRT::strcmp(aTopic, "profile-before-change")) {
         // Write out the old datasource's contents.
         if (mInner) {
-            nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(mInner);
+            nsIRDFRemoteDataSource* remote = do_QueryInterface(mInner);
             if (remote)
                 remote->Flush();
         }
@@ -509,8 +507,8 @@ LocalStoreImpl::Observe(nsISupports *aSu
         mInner = do_CreateInstance(NS_RDF_DATASOURCE_CONTRACTID_PREFIX "in-memory-datasource");
 
         if (!nsCRT::strcmp(NS_ConvertUTF16toUTF8(someData).get(), "shutdown-cleanse")) {
-            nsCOMPtr<nsIFile> aFile;
-            rv = NS_GetSpecialDirectory(NS_APP_LOCALSTORE_50_FILE, getter_AddRefs(aFile));
+            nsIFile* aFile = nsnull;
+            rv = NS_GetSpecialDirectory(NS_APP_LOCALSTORE_50_FILE, &aFile);
             if (NS_SUCCEEDED(rv))
                 rv = aFile->Remove(PR_FALSE);
         }
diff --git a/rdf/util/public/nsRDFResource.h b/rdf/util/public/nsRDFResource.h
--- a/rdf/util/public/nsRDFResource.h
+++ b/rdf/util/public/nsRDFResource.h
@@ -51,7 +51,7 @@ class nsIRDFService;
  * This simple base class implements nsIRDFResource, and can be used as a
  * superclass for more sophisticated resource implementations.
  */
-class nsRDFResource : public nsIRDFResource {
+class nsRDFResource : public XPCOMGCFinalizedObject, public nsIRDFResource {
 public:
 
     NS_DECL_ISUPPORTS
@@ -60,7 +60,6 @@ public:
     NS_IMETHOD EqualsNode(nsIRDFNode* aNode, PRBool* aResult);
 
     // nsIRDFResource methods:
-    NS_IMETHOD Init(const char* aURI);
     NS_IMETHOD GetValue(char* *aURI);
     NS_IMETHOD GetValueUTF8(nsACString& aResult);
     NS_IMETHOD GetValueConst(const char** aURI);
@@ -69,20 +68,35 @@ public:
     NS_IMETHOD ReleaseDelegate(const char* aKey);
 
     // nsRDFResource methods:
-    nsRDFResource(void);
-    virtual ~nsRDFResource(void);
+    nsRDFResource(const nsACString &aURI)
+        : mURI(aURI)
+        , mDelegates(nsnull) { }
 
-protected:
-    static nsIRDFService* gRDFService;
-    static nsrefcnt gRDFServiceRefCnt;
+    const char* GetInternal()
+    {
+        return mURI.get();
+    }
 
 protected:
     nsCString mURI;
 
-    struct DelegateEntry {
-        nsCString             mKey;
+    struct DelegateEntry : public XPCOMGCObject {
+        DelegateEntry(nsISupports* delegate, const char *key)
+            : mDelegate(delegate)
+            , mNext(nsnull)
+        {
+            strcpy(mKey, key);
+        }
+
         nsCOMPtr<nsISupports> mDelegate;
         DelegateEntry*        mNext;
+        char                  mKey[1];
+
+        static void* operator new(size_t size, const char *key)
+        {
+            return MMgc::GCObject::operator new(size, NS_GetGC(),
+                                                strlen(key));
+        }
     };
 
     DelegateEntry* mDelegates;
diff --git a/rdf/util/src/nsRDFResource.cpp b/rdf/util/src/nsRDFResource.cpp
--- a/rdf/util/src/nsRDFResource.cpp
+++ b/rdf/util/src/nsRDFResource.cpp
@@ -45,36 +45,6 @@
 #include "nsComponentManagerUtils.h"
 #include "nsServiceManagerUtils.h"
 
-static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
-
-nsIRDFService* nsRDFResource::gRDFService = nsnull;
-nsrefcnt nsRDFResource::gRDFServiceRefCnt = 0;
-
-////////////////////////////////////////////////////////////////////////////////
-
-nsRDFResource::nsRDFResource(void)
-    : mDelegates(nsnull)
-{
-}
-
-nsRDFResource::~nsRDFResource(void)
-{
-    // Release all of the delegate objects
-    while (mDelegates) {
-        DelegateEntry* doomed = mDelegates;
-        mDelegates = mDelegates->mNext;
-        delete doomed;
-    }
-
-    if (!gRDFService)
-        return;
-
-    gRDFService->UnregisterResource(this);
-
-    if (--gRDFServiceRefCnt == 0)
-        NS_RELEASE(gRDFService);
-}
-
 NS_IMPL_THREADSAFE_ISUPPORTS2(nsRDFResource, nsIRDFResource, nsIRDFNode)
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -106,24 +76,6 @@ nsRDFResource::EqualsNode(nsIRDFNode* aN
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIRDFResource methods:
-
-NS_IMETHODIMP
-nsRDFResource::Init(const char* aURI)
-{
-    NS_PRECONDITION(aURI != nsnull, "null ptr");
-    if (! aURI)
-        return NS_ERROR_NULL_POINTER;
-
-    mURI = aURI;
-
-    if (gRDFServiceRefCnt++ == 0) {
-        nsresult rv = CallGetService(kRDFServiceCID, &gRDFService);
-        if (NS_FAILED(rv)) return rv;
-    }
-
-    // don't replace an existing resource with the same URI automatically
-    return gRDFService->RegisterResource(this, PR_TRUE);
-}
 
 NS_IMETHODIMP
 nsRDFResource::GetValue(char* *aURI)
@@ -177,7 +129,7 @@ nsRDFResource::GetDelegate(const char* a
 
     DelegateEntry* entry = mDelegates;
     while (entry) {
-        if (entry->mKey.Equals(aKey)) {
+        if (!strcmp(entry->mKey, aKey)) {
             rv = entry->mDelegate->QueryInterface(aIID, aResult);
             return rv;
         }
@@ -193,7 +145,7 @@ nsRDFResource::GetDelegate(const char* a
     PRInt32 i = mURI.FindChar(':');
     contractID += StringHead(mURI, i);
 
-    nsCOMPtr<nsIRDFDelegateFactory> delegateFactory =
+    nsIRDFDelegateFactory* delegateFactory =
              do_CreateInstance(contractID.get(), &rv);
     if (NS_FAILED(rv)) return rv;
 
@@ -201,24 +153,10 @@ nsRDFResource::GetDelegate(const char* a
     if (NS_FAILED(rv)) return rv;
 
     // Okay, we've successfully created a delegate. Let's remember it.
-    entry = new DelegateEntry;
-    if (! entry) {
-        NS_RELEASE(*reinterpret_cast<nsISupports**>(aResult));
-        return NS_ERROR_OUT_OF_MEMORY;
-    }
-    
-    entry->mKey      = aKey;
-    entry->mDelegate = do_QueryInterface(*reinterpret_cast<nsISupports**>(aResult), &rv);
-    if (NS_FAILED(rv)) {
-        NS_ERROR("nsRDFResource::GetDelegate(): can't QI to nsISupports!");
+    entry = new (aKey) DelegateEntry(*reinterpret_cast<nsISupports**>(aResult),
 
-        delete entry;
-        NS_RELEASE(*reinterpret_cast<nsISupports**>(aResult));
-        return NS_ERROR_FAILURE;
-    }
-
+                                     aKey);
     entry->mNext     = mDelegates;
-
     mDelegates = entry;
 
     return NS_OK;
@@ -235,9 +173,8 @@ nsRDFResource::ReleaseDelegate(const cha
     DelegateEntry** link = &mDelegates;
 
     while (entry) {
-        if (entry->mKey.Equals(aKey)) {
+        if (!strcmp(entry->mKey, aKey)) {
             *link = entry->mNext;
-            delete entry;
             return NS_OK;
         }
 
diff --git a/xpfe/components/directory/nsDirectoryViewer.cpp b/xpfe/components/directory/nsDirectoryViewer.cpp
--- a/xpfe/components/directory/nsDirectoryViewer.cpp
+++ b/xpfe/components/directory/nsDirectoryViewer.cpp
@@ -140,7 +140,6 @@ nsHTTPIndex::GetInterface(const nsIID &a
         if (!mRequestor)
           return NS_ERROR_NO_INTERFACE;
         *aResult = static_cast<nsIFTPEventSink*>(this);
-        NS_ADDREF(this);
         return NS_OK;
     }
 
@@ -149,11 +148,11 @@ nsHTTPIndex::GetInterface(const nsIID &a
         if (!mRequestor) 
             return NS_ERROR_NO_INTERFACE;
 
-        nsCOMPtr<nsIDOMWindow> aDOMWindow = do_GetInterface(mRequestor);
+        nsIDOMWindow* aDOMWindow = do_GetInterface(mRequestor);
         if (!aDOMWindow) 
             return NS_ERROR_NO_INTERFACE;
 
-        nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
+        nsIWindowWatcher* wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
         
         return wwatch->GetNewPrompter(aDOMWindow, (nsIPrompt**)aResult);
     }  
@@ -163,11 +162,11 @@ nsHTTPIndex::GetInterface(const nsIID &a
         if (!mRequestor) 
             return NS_ERROR_NO_INTERFACE;
 
-        nsCOMPtr<nsIDOMWindow> aDOMWindow = do_GetInterface(mRequestor);
+        nsIDOMWindow* aDOMWindow = do_GetInterface(mRequestor);
         if (!aDOMWindow) 
             return NS_ERROR_NO_INTERFACE;
 
-        nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
+        nsIWindowWatcher* wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
         
         return wwatch->GetNewAuthPrompter(aDOMWindow, (nsIAuthPrompt**)aResult);
     }  
@@ -177,12 +176,11 @@ nsHTTPIndex::GetInterface(const nsIID &a
         if (!mRequestor) 
             return NS_ERROR_NO_INTERFACE;
 
-        nsCOMPtr<nsIProgressEventSink> sink = do_GetInterface(mRequestor);
+        nsIProgressEventSink* sink = do_GetInterface(mRequestor);
         if (!sink) 
             return NS_ERROR_NO_INTERFACE;
         
         *aResult = sink;
-        NS_ADDREF((nsISupports*)*aResult);
         return NS_OK;
     }
 
@@ -194,7 +192,7 @@ nsHTTPIndex::OnFTPControlLog(PRBool serv
 {
     NS_ENSURE_TRUE(mRequestor, NS_OK);
 
-    nsCOMPtr<nsIScriptGlobalObject> scriptGlobal(do_GetInterface(mRequestor));
+    nsIScriptGlobalObject* scriptGlobal(do_GetInterface(mRequestor));
     NS_ENSURE_TRUE(scriptGlobal, NS_OK);
 
     nsIScriptContext *context = scriptGlobal->GetContext();
@@ -271,7 +269,7 @@ nsHTTPIndex::OnStartRequest(nsIRequest *
     mBindToGlobalObject = PR_FALSE;
 
     // Now get the content viewer container's script object.
-    nsCOMPtr<nsIScriptGlobalObject> scriptGlobal(do_GetInterface(mRequestor));
+    nsIScriptGlobalObject* scriptGlobal(do_GetInterface(mRequestor));
     NS_ENSURE_TRUE(scriptGlobal, NS_ERROR_FAILURE);
 
     nsIScriptContext *context = scriptGlobal->GetContext();
@@ -283,15 +281,15 @@ nsHTTPIndex::OnStartRequest(nsIRequest *
 
     // Using XPConnect, wrap the HTTP index object...
     static NS_DEFINE_CID(kXPConnectCID, NS_XPCONNECT_CID);
-    nsCOMPtr<nsIXPConnect> xpc(do_GetService(kXPConnectCID, &rv));
+    nsIXPConnect* xpc(do_GetService(kXPConnectCID, &rv));
     if (NS_FAILED(rv)) return rv;
 
-    nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
+    nsIXPConnectJSObjectHolder* wrapper = nsnull;
     rv = xpc->WrapNative(jscontext,
                          global,
                          static_cast<nsIHTTPIndex*>(this),
                          NS_GET_IID(nsIHTTPIndex),
-                         getter_AddRefs(wrapper));
+                         &wrapper);
 
     NS_ASSERTION(NS_SUCCEEDED(rv), "unable to xpconnect-wrap http-index");
     if (NS_FAILED(rv)) return rv;
@@ -313,26 +311,26 @@ nsHTTPIndex::OnStartRequest(nsIRequest *
       return NS_ERROR_FAILURE;
   }
   if (!aContext) {
-    nsCOMPtr<nsIChannel> channel(do_QueryInterface(request));
+    nsIChannel* channel(do_QueryInterface(request));
     NS_ASSERTION(channel, "request should be a channel");
 
     // lets hijack the notifications:
     channel->SetNotificationCallbacks(this);
 
     // now create the top most resource
-    nsCOMPtr<nsIURI> uri;
-    channel->GetURI(getter_AddRefs(uri));
+    nsIURI* uri = nsnull;
+    channel->GetURI(&uri);
       
     nsCAutoString entryuriC;
     uri->GetSpec(entryuriC);
 
-    nsCOMPtr<nsIRDFResource> entry;
-    rv = mDirRDF->GetResource(entryuriC, getter_AddRefs(entry));
+    nsIRDFResource* entry = nsnull;
+    rv = mDirRDF->GetResource(entryuriC, &entry);
     
     NS_ConvertUTF8toUTF16 uriUnicode(entryuriC);
 
-    nsCOMPtr<nsIRDFLiteral> URLVal;
-    rv = mDirRDF->GetLiteral(uriUnicode.get(), getter_AddRefs(URLVal));
+    nsIRDFLiteral* URLVal = nsnull;
+    rv = mDirRDF->GetLiteral(uriUnicode.get(), &URLVal);
 
     Assert(entry, kNC_URL, URLVal, PR_TRUE);
     mDirectory = do_QueryInterface(entry);
@@ -375,8 +373,8 @@ nsHTTPIndex::OnStopRequest(nsIRequest *r
   nsXPIDLCString commentStr;
   mParser->GetComment(getter_Copies(commentStr));
 
-  nsCOMPtr<nsIRDFLiteral> comment;
-  rv = mDirRDF->GetLiteral(NS_ConvertASCIItoUTF16(commentStr).get(), getter_AddRefs(comment));
+  nsIRDFLiteral* comment = nsnull;
+  rv = mDirRDF->GetLiteral(NS_ConvertASCIItoUTF16(commentStr).get(), &comment);
   if (NS_FAILED(rv)) return rv;
 
   rv = Assert(mDirectory, kNC_Comment, comment, PR_TRUE);
@@ -410,7 +408,7 @@ nsHTTPIndex::OnIndexAvailable(nsIRequest
 nsHTTPIndex::OnIndexAvailable(nsIRequest* aRequest, nsISupports *aContext,
                               nsIDirIndex* aIndex)
 {
-  nsCOMPtr<nsIRDFResource>	parentRes = do_QueryInterface(aContext);
+  nsIRDFResource*	parentRes = do_QueryInterface(aContext);
   if (!parentRes) {
     NS_ERROR("Could not obtain parent resource");
     return(NS_ERROR_UNEXPECTED);
@@ -450,8 +448,8 @@ nsHTTPIndex::OnIndexAvailable(nsIRequest
       entryuriC.Append('/');
   }
 
-  nsCOMPtr<nsIRDFResource> entry;
-  rv = mDirRDF->GetResource(entryuriC, getter_AddRefs(entry));
+  nsIRDFResource* entry = nsnull;
+  rv = mDirRDF->GetResource(entryuriC, &entry);
 
   // At this point, we'll (hopefully) have found the filename and
   // constructed a resource for it, stored in entry. So now take a
@@ -459,7 +457,7 @@ nsHTTPIndex::OnIndexAvailable(nsIRequest
   // datasource.
 
   if (entry && NS_SUCCEEDED(rv)) {
-    nsCOMPtr<nsIRDFLiteral> lit;
+    nsIRDFLiteral* lit = nsnull;
     nsString str;
 
     // For gopher, the target is the filename. We still have to do all
@@ -471,7 +469,7 @@ nsHTTPIndex::OnIndexAvailable(nsIRequest
       str.AssignWithConversion(entryuriC.get());
     }
 
-    rv = mDirRDF->GetLiteral(str.get(), getter_AddRefs(lit));
+    rv = mDirRDF->GetLiteral(str.get(), &lit);
 
     if (NS_SUCCEEDED(rv)) {
       rv = Assert(entry, kNC_URL, lit, PR_TRUE);
@@ -485,7 +483,7 @@ nsHTTPIndex::OnIndexAvailable(nsIRequest
       if (xpstr.Last() == '/')
         xpstr.Truncate(xpstr.Length() - 1);
 
-      rv = mDirRDF->GetLiteral(xpstr.get(), getter_AddRefs(lit));
+      rv = mDirRDF->GetLiteral(xpstr.get(), &lit);
       if (NS_FAILED(rv)) return rv;
       rv = Assert(entry, kNC_Description, lit, PR_TRUE);
       if (NS_FAILED(rv)) return rv;
@@ -499,8 +497,8 @@ nsHTTPIndex::OnIndexAvailable(nsIRequest
         PRInt32 intSize;
         LL_L2I(intSize, size);
         // XXX RDF should support 64 bit integers (bug 240160)
-        nsCOMPtr<nsIRDFInt> val;
-        rv = mDirRDF->GetIntLiteral(intSize, getter_AddRefs(val));
+        nsIRDFInt* val = nsnull;
+        rv = mDirRDF->GetIntLiteral(intSize, &val);
         if (NS_FAILED(rv)) return rv;
         rv = Assert(entry, kNC_ContentLength, val, PR_TRUE);
         if (NS_FAILED(rv)) return rv;
@@ -511,8 +509,8 @@ nsHTTPIndex::OnIndexAvailable(nsIRequest
       rv = aIndex->GetLastModified(&tm);
       if (NS_FAILED(rv)) return rv;
       if (tm != -1) {
-        nsCOMPtr<nsIRDFDate> val;
-        rv = mDirRDF->GetDateLiteral(tm, getter_AddRefs(val));
+        nsIRDFDate* val = nsnull;
+        rv = mDirRDF->GetDateLiteral(tm, &val);
         if (NS_FAILED(rv)) return rv;
         rv = Assert(entry, kNC_LastModified, val, PR_TRUE);
       }
@@ -522,16 +520,16 @@ nsHTTPIndex::OnIndexAvailable(nsIRequest
       rv = aIndex->GetType(&type);
       switch (type) {
       case nsIDirIndex::TYPE_UNKNOWN:
-        rv = mDirRDF->GetLiteral(NS_LITERAL_STRING("UNKNOWN").get(), getter_AddRefs(lit));
+        rv = mDirRDF->GetLiteral(NS_LITERAL_STRING("UNKNOWN").get(), &lit);
         break;
       case nsIDirIndex::TYPE_DIRECTORY:
-        rv = mDirRDF->GetLiteral(NS_LITERAL_STRING("DIRECTORY").get(), getter_AddRefs(lit));
+        rv = mDirRDF->GetLiteral(NS_LITERAL_STRING("DIRECTORY").get(), &lit);
         break;
       case nsIDirIndex::TYPE_FILE:
-        rv = mDirRDF->GetLiteral(NS_LITERAL_STRING("FILE").get(), getter_AddRefs(lit));
+        rv = mDirRDF->GetLiteral(NS_LITERAL_STRING("FILE").get(), &lit);
         break;
       case nsIDirIndex::TYPE_SYMLINK:
-        rv = mDirRDF->GetLiteral(NS_LITERAL_STRING("SYMLINK").get(), getter_AddRefs(lit));
+        rv = mDirRDF->GetLiteral(NS_LITERAL_STRING("SYMLINK").get(), &lit);
         break;
       }
       
@@ -599,12 +597,6 @@ nsHTTPIndex::~nsHTTPIndex()
 
     mConnectionList = nsnull;
     mNodeList = nsnull;
-    
-    if (mDirRDF)
-      {
-        // UnregisterDataSource() may fail; just ignore errors
-        mDirRDF->UnregisterDataSource(this);
-      }
 }
 
 
@@ -700,8 +692,8 @@ nsHTTPIndex::Init(nsIURI* aBaseURL)
   if (NS_FAILED(rv)) return rv;
   
   // Mark the base url as a container
-  nsCOMPtr<nsIRDFResource> baseRes;
-  mDirRDF->GetResource(mBaseURL, getter_AddRefs(baseRes));
+  nsIRDFResource* baseRes = nsnull;
+  mDirRDF->GetResource(mBaseURL, &baseRes);
   Assert(baseRes, kNC_IsContainer, kTrueLiteral, PR_TRUE);
 
   return NS_OK;
@@ -722,7 +714,6 @@ nsHTTPIndex::Create(nsIURI* aBaseURL, ns
   nsresult rv = result->Init(aBaseURL);
   if (NS_SUCCEEDED(rv))
   {
-    NS_ADDREF(result);
     *aResult = result;
   }
   else
@@ -745,7 +736,7 @@ NS_IMETHODIMP
 NS_IMETHODIMP
 nsHTTPIndex::GetDataSource(nsIRDFDataSource** _result)
 {
-  NS_ADDREF(*_result = this);
+  *_result = this;
   return NS_OK;
 }
 
@@ -756,10 +747,10 @@ nsHTTPIndex::GetDataSource(nsIRDFDataSou
 // Do NOT try to get the destination of a uri in any other way
 void nsHTTPIndex::GetDestination(nsIRDFResource* r, nsXPIDLCString& dest) {
   // First try the URL attribute
-  nsCOMPtr<nsIRDFNode> node;
+  nsIRDFNode* node = nsnull;
   
-  GetTarget(r, kNC_URL, PR_TRUE, getter_AddRefs(node));
-  nsCOMPtr<nsIRDFLiteral> url;
+  GetTarget(r, kNC_URL, PR_TRUE, &node);
+  nsIRDFLiteral* url = nsnull;
   
   if (node)
     url = do_QueryInterface(node);
@@ -797,8 +788,8 @@ PRBool
 PRBool
 nsHTTPIndex::isWellknownContainerURI(nsIRDFResource *r)
 {
-  nsCOMPtr<nsIRDFNode> node;
-  GetTarget(r, kNC_IsContainer, PR_TRUE, getter_AddRefs(node));
+  nsIRDFNode* node = nsnull;
+  GetTarget(r, kNC_IsContainer, PR_TRUE, &node);
 
   PRBool isContainerFlag = PR_FALSE;
 
@@ -897,7 +888,6 @@ nsHTTPIndex::GetTarget(nsIRDFResource *a
 	{
 		// fake out the generic builder (i.e. return anything in this case)
 		// so that search containers never appear to be empty
-		NS_IF_ADDREF(aSource);
 		*_retval = aSource;
 		return(NS_OK);
 	}
@@ -1019,11 +1009,11 @@ nsHTTPIndex::FireTimer(nsITimer* aTimer,
         httpIndex->mConnectionList->Count(&numItems);
         if (numItems > 0)
         {
-          nsCOMPtr<nsISupports>   isupports;
-          httpIndex->mConnectionList->GetElementAt((PRUint32)0, getter_AddRefs(isupports));
+          nsISupports*   isupports = nsnull;
+          httpIndex->mConnectionList->GetElementAt((PRUint32)0, &isupports);
           httpIndex->mConnectionList->RemoveElementAt((PRUint32)0);
           
-          nsCOMPtr<nsIRDFResource>    aSource;
+          nsIRDFResource*    aSource = nsnull;
           if (isupports)  aSource = do_QueryInterface(isupports);
           
           nsXPIDLCString uri;
@@ -1037,12 +1027,12 @@ nsHTTPIndex::FireTimer(nsITimer* aTimer,
           }
           
           nsresult            rv = NS_OK;
-          nsCOMPtr<nsIURI>	url;
+          nsIURI*	url = nsnull;
           
-          rv = NS_NewURI(getter_AddRefs(url), uri.get());
-          nsCOMPtr<nsIChannel>	channel;
+          rv = NS_NewURI(&url, uri.get());
+          nsIChannel*	channel = nsnull;
           if (NS_SUCCEEDED(rv) && (url)) {
-            rv = NS_NewChannel(getter_AddRefs(channel), url, nsnull, nsnull);
+            rv = NS_NewChannel(&channel, url, nsnull, nsnull);
           }
           if (NS_SUCCEEDED(rv) && (channel)) {
             channel->SetNotificationCallbacks(httpIndex);
@@ -1062,24 +1052,24 @@ nsHTTPIndex::FireTimer(nsITimer* aTimer,
             PRInt32 loop;
             for (loop=0; loop<(PRInt32)numItems; loop++)
             {
-                nsCOMPtr<nsISupports>   isupports;
-                httpIndex->mNodeList->GetElementAt((PRUint32)0, getter_AddRefs(isupports));
+                nsISupports*   isupports = nsnull;
+                httpIndex->mNodeList->GetElementAt((PRUint32)0, &isupports);
                 httpIndex->mNodeList->RemoveElementAt((PRUint32)0);
-                nsCOMPtr<nsIRDFResource>    src;
+                nsIRDFResource*    src = nsnull;
                 if (isupports)  src = do_QueryInterface(isupports);
-                httpIndex->mNodeList->GetElementAt((PRUint32)0, getter_AddRefs(isupports));
+                httpIndex->mNodeList->GetElementAt((PRUint32)0, &isupports);
                 httpIndex->mNodeList->RemoveElementAt((PRUint32)0);
-                nsCOMPtr<nsIRDFResource>    prop;
+                nsIRDFResource*    prop = nsnull;
                 if (isupports)  prop = do_QueryInterface(isupports);
                 
-                httpIndex->mNodeList->GetElementAt((PRUint32)0, getter_AddRefs(isupports));
+                httpIndex->mNodeList->GetElementAt((PRUint32)0, &isupports);
                 httpIndex->mNodeList->RemoveElementAt((PRUint32)0);
-                nsCOMPtr<nsIRDFNode>    target;
+                nsIRDFNode*    target = nsnull;
                 if (isupports)  target = do_QueryInterface(isupports);
                 
                 if (src && prop && target)
                 {
-                    if (prop.get() == httpIndex->kNC_Loading)
+                    if (prop == httpIndex->kNC_Loading)
                     {
                         httpIndex->Unassert(src, prop, target);
                     }
@@ -1263,8 +1253,8 @@ nsHTTPIndex::ArcLabelsOut(nsIRDFResource
 
 	*_retval = nsnull;
 
-	nsCOMPtr<nsISupportsArray> array;
-	rv = NS_NewISupportsArray(getter_AddRefs(array));
+	nsISupportsArray* array = nsnull;
+	rv = NS_NewISupportsArray(&array);
 	if (NS_FAILED(rv)) return rv;
 
 	if (isWellknownContainerURI(aSource))
@@ -1274,15 +1264,15 @@ nsHTTPIndex::ArcLabelsOut(nsIRDFResource
 
 	if (mInner)
 	{
-		nsCOMPtr<nsISimpleEnumerator>	anonArcs;
-		rv = mInner->ArcLabelsOut(aSource, getter_AddRefs(anonArcs));
+		nsISimpleEnumerator*	anonArcs = nsnull;
+		rv = mInner->ArcLabelsOut(aSource, &anonArcs);
 		PRBool	hasResults = PR_TRUE;
 		while (NS_SUCCEEDED(rv) &&
                        NS_SUCCEEDED(anonArcs->HasMoreElements(&hasResults)) &&
                        hasResults == PR_TRUE)
 		{
-			nsCOMPtr<nsISupports>	anonArc;
-			if (NS_FAILED(anonArcs->GetNext(getter_AddRefs(anonArc))))
+			nsISupports*	anonArc = nsnull;
+			if (NS_FAILED(anonArcs->GetNext(&anonArc)))
 				break;
 			array->AppendElement(anonArc);
 		}
@@ -1384,7 +1374,7 @@ nsDirectoryViewerFactory::CreateInstance
   nsresult rv;
 
   // OK - are we going to be using the html listing or not?
-  nsCOMPtr<nsIPrefBranch> prefSrv = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
+  nsIPrefBranch* prefSrv = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
   if (NS_FAILED(rv)) return rv;
 
   PRBool useXUL = PR_FALSE;  
@@ -1406,7 +1396,7 @@ nsDirectoryViewerFactory::CreateInstance
     // load in its place.
     
     // Create a dummy loader that will load a stub XUL document.
-    nsCOMPtr<nsICategoryManager> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
+    nsICategoryManager* catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
     if (NS_FAILED(rv))
       return rv;
     nsXPIDLCString contractID;
@@ -1415,20 +1405,20 @@ nsDirectoryViewerFactory::CreateInstance
     if (NS_FAILED(rv))
       return rv;
 
-    nsCOMPtr<nsIDocumentLoaderFactory> factory(do_GetService(contractID, &rv));
+    nsIDocumentLoaderFactory* factory(do_GetService(contractID, &rv));
     if (NS_FAILED(rv)) return rv;
     
-    nsCOMPtr<nsIURI> uri;
-    rv = NS_NewURI(getter_AddRefs(uri), "chrome://communicator/content/directory/directory.xul");
+    nsIURI* uri = nsnull;
+    rv = NS_NewURI(&uri, "chrome://communicator/content/directory/directory.xul");
     if (NS_FAILED(rv)) return rv;
     
-    nsCOMPtr<nsIChannel> channel;
-    rv = NS_NewChannel(getter_AddRefs(channel), uri, nsnull, aLoadGroup);
+    nsIChannel* channel = nsnull;
+    rv = NS_NewChannel(&channel, uri, nsnull, aLoadGroup);
     if (NS_FAILED(rv)) return rv;
     
-    nsCOMPtr<nsIStreamListener> listener;
+    nsIStreamListener* listener = nsnull;
     rv = factory->CreateInstance(aCommand, channel, aLoadGroup, "application/vnd.mozilla.xul+xml",
-                                 aContainer, aExtraInfo, getter_AddRefs(listener),
+                                 aContainer, aExtraInfo, &listener,
                                  aDocViewerResult);
     if (NS_FAILED(rv)) return rv;
 
@@ -1436,22 +1426,21 @@ nsDirectoryViewerFactory::CreateInstance
     if (NS_FAILED(rv)) return rv;
     
     // Create an HTTPIndex object so that we can stuff it into the script context
-    nsCOMPtr<nsIURI> baseuri;
-    rv = aChannel->GetURI(getter_AddRefs(baseuri));
+    nsIURI* baseuri = nsnull;
+    rv = aChannel->GetURI(&baseuri);
     if (NS_FAILED(rv)) return rv;
     
-    nsCOMPtr<nsIInterfaceRequestor> requestor = do_QueryInterface(aContainer,&rv);
+    nsIInterfaceRequestor* requestor = do_QueryInterface(aContainer,&rv);
     if (NS_FAILED(rv)) return rv;
     
-    nsCOMPtr<nsIHTTPIndex> httpindex;
-    rv = nsHTTPIndex::Create(baseuri, requestor, getter_AddRefs(httpindex));
+    nsIHTTPIndex* httpindex = nsnull;
+    rv = nsHTTPIndex::Create(baseuri, requestor, &httpindex);
     if (NS_FAILED(rv)) return rv;
     
     // Now shanghai the stream into our http-index parsing datasource
     // wrapper beastie.
     listener = do_QueryInterface(httpindex,&rv);
-    *aDocListenerResult = listener.get();
-    NS_ADDREF(*aDocListenerResult);
+    *aDocListenerResult = listener;
     
     return NS_OK;
   }
@@ -1461,7 +1450,7 @@ nsDirectoryViewerFactory::CreateInstance
   (void)aChannel->SetContentType(NS_LITERAL_CSTRING("text/html"));
 
   // Otherwise, lets use the html listing
-  nsCOMPtr<nsICategoryManager> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
+  nsICategoryManager* catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
   if (NS_FAILED(rv))
     return rv;
   nsXPIDLCString contractID;
@@ -1470,24 +1459,24 @@ nsDirectoryViewerFactory::CreateInstance
   if (NS_FAILED(rv))
     return rv;
 
-  nsCOMPtr<nsIDocumentLoaderFactory> factory(do_GetService(contractID, &rv));
+  nsIDocumentLoaderFactory* factory(do_GetService(contractID, &rv));
   if (NS_FAILED(rv)) return rv;
   
-  nsCOMPtr<nsIStreamListener> listener;
+  nsIStreamListener* listener = nsnull;
 
   if (viewSource) {
     rv = factory->CreateInstance("view-source", aChannel, aLoadGroup, "text/html; x-view-type=view-source",
-                                 aContainer, aExtraInfo, getter_AddRefs(listener),
+                                 aContainer, aExtraInfo, &listener,
                                  aDocViewerResult);
   } else {
     rv = factory->CreateInstance("view", aChannel, aLoadGroup, "text/html",
-                                 aContainer, aExtraInfo, getter_AddRefs(listener),
+                                 aContainer, aExtraInfo, &listener,
                                  aDocViewerResult);
   }
 
   if (NS_FAILED(rv)) return rv;
 
-  nsCOMPtr<nsIStreamConverterService> scs = do_GetService("@mozilla.org/streamConverters;1", &rv);
+  nsIStreamConverterService* scs = do_GetService("@mozilla.org/streamConverters;1", &rv);
   if (NS_FAILED(rv)) return rv;
 
   rv = scs->AsyncConvertData("application/http-index-format",
diff --git a/xpfe/components/intl/nsCharsetMenu.cpp b/xpfe/components/intl/nsCharsetMenu.cpp
--- a/xpfe/components/intl/nsCharsetMenu.cpp
+++ b/xpfe/components/intl/nsCharsetMenu.cpp
@@ -790,9 +790,6 @@ nsresult nsCharsetMenu::Init()
 
 nsresult nsCharsetMenu::Done() 
 {
-  nsresult res = NS_OK;
-  res = mRDFService->UnregisterDataSource(this);
-
   NS_IF_RELEASE(kNC_BrowserAutodetMenuRoot);
   NS_IF_RELEASE(kNC_BrowserCharsetMenuRoot);
   NS_IF_RELEASE(kNC_BrowserMoreCharsetMenuRoot);
@@ -814,7 +811,7 @@ nsresult nsCharsetMenu::Done()
   NS_IF_RELEASE(kRDF_type);
   NS_IF_RELEASE(mInner);
 
-  return res;
+  return NS_OK;
 }
 
 nsresult nsCharsetMenu::SetCharsetCheckmark(nsString * aCharset,