root-nsIMemory
author Benjamin Smedberg <benjamin@smedbergs.us>
Sat, 26 Jul 2008 22:49:39 -0400
changeset 167 a4da40849f5436e629c5732f4368c6c48189637f
parent 86 25758f819266acd05cd2104d6205640f6c705a4b
permissions -rw-r--r--
State as of now

* * *

diff --git a/xpcom/base/nsMemoryImpl.cpp b/xpcom/base/nsMemoryImpl.cpp
--- a/xpcom/base/nsMemoryImpl.cpp
+++ b/xpcom/base/nsMemoryImpl.cpp
@@ -241,8 +241,7 @@ nsMemoryImpl::FlushMemory(const PRUnicha
         rv = RunFlushers(aReason);
     }
     else {
-        sFlushEvent.mReason = aReason;
-        rv = NS_DispatchToMainThread(&sFlushEvent, NS_DISPATCH_NORMAL);
+        rv = NS_DispatchToMainThread(new FlushEvent(aReason), NS_DISPATCH_NORMAL);
     }
 
     return rv;
@@ -272,9 +271,6 @@ nsMemoryImpl::FlushEvent::Run()
 
 PRInt32
 nsMemoryImpl::sIsFlushing = 0;
-
-nsMemoryImpl::FlushEvent
-nsMemoryImpl::sFlushEvent;
 
 XPCOM_API(void*)
 NS_Alloc(PRSize size)
@@ -344,8 +340,10 @@ nsresult
 nsresult
 NS_GetMemoryManager(nsIMemory* *result)
 {
-    if (!sGlobalMemory)
+    if (!sGlobalMemory) {
         sGlobalMemory = new nsMemoryImpl();
+        NS_RootUntilShutdown(sGlobalMemory);
+    }
 
     *result = sGlobalMemory;
     return NS_OK;
diff --git a/xpcom/base/nsMemoryImpl.h b/xpcom/base/nsMemoryImpl.h
--- a/xpcom/base/nsMemoryImpl.h
+++ b/xpcom/base/nsMemoryImpl.h
@@ -64,13 +64,17 @@ public:
 
 protected:
     struct FlushEvent : public nsIRunnable {
+    public:
+
+        FlushEvent(const PRUnichar *reason)
+            : mReason(reason) { }
+
         NS_DECL_ISUPPORTS_INHERITED
         NS_DECL_NSIRUNNABLE
         const PRUnichar* mReason;
     };
 
     static PRInt32    sIsFlushing;
-    static FlushEvent sFlushEvent;
 };
 
 #endif // nsMemoryImpl_h__