bug 402763: cycle collect on memory-pressure notification, r/sr=stuart a=schrep

This commit is contained in:
jonas@sicking.cc 2007-11-06 13:47:35 -08:00
Родитель 3986314bbc
Коммит 6699d2a5b3
2 изменённых файлов: 28 добавлений и 3 удалений

Просмотреть файл

@ -53,7 +53,7 @@
#include "nsIWidget.h"
#include "nsGUIEvent.h"
#include "nsIParser.h"
#include "nsCycleCollector.h"
#include "nsJSEnvironment.h"
#ifdef MOZ_ENABLE_GTK2
#include <gdk/gdkx.h>
@ -341,8 +341,8 @@ nsDOMWindowUtils::GarbageCollect()
return NS_ERROR_DOM_SECURITY_ERR;
#endif
nsCycleCollector_collect();
nsCycleCollector_collect();
nsJSContext::CC();
nsJSContext::CC();
return NS_OK;
}

Просмотреть файл

@ -281,6 +281,27 @@ nsUserActivityObserver::Observe(nsISupports* aSubject, const char* aTopic,
return NS_OK;
}
// nsCCMemoryPressureObserver observes the memory-pressure notifications
// and forces a cycle collection when it happens.
class nsCCMemoryPressureObserver : public nsIObserver
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
};
NS_IMPL_ISUPPORTS1(nsCCMemoryPressureObserver, nsIObserver)
NS_IMETHODIMP
nsCCMemoryPressureObserver::Observe(nsISupports* aSubject, const char* aTopic,
const PRUnichar* aData)
{
nsJSContext::CC();
return NS_OK;
}
/****************************************************************
************************** AutoFree ****************************
****************************************************************/
@ -3620,6 +3641,10 @@ nsJSRuntime::Init()
obs->AddObserver(activityObserver, "user-interaction-active", PR_FALSE);
obs->AddObserver(activityObserver, "xpcom-shutdown", PR_FALSE);
nsIObserver* ccMemPressureObserver = new nsCCMemoryPressureObserver();
NS_ENSURE_TRUE(ccMemPressureObserver, NS_ERROR_OUT_OF_MEMORY);
obs->AddObserver(ccMemPressureObserver, "memory-pressure", PR_FALSE);
rv = CallGetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &sSecurityManager);
sIsInitialized = NS_SUCCEEDED(rv);