Bug 936964 (part 3, attempt 2) - Make nsCycleCollector ref-counted. r=mccr8.

--HG--
extra : rebase_source : ebda496b8cba0464280eb0dc7bae9aca137e2e25
This commit is contained in:
Nicholas Nethercote 2013-11-25 15:57:53 -08:00
parent 15e6bd0f25
commit d27c541046

View File

@ -995,8 +995,10 @@ enum ccType {
// Top level structure for the cycle collector.
////////////////////////////////////////////////////////////////////////
class nsCycleCollector
class nsCycleCollector : public nsISupports
{
NS_DECL_ISUPPORTS
bool mCollectionInProgress;
// mScanInProgress should be false when we're collecting white objects.
bool mScanInProgress;
@ -1027,7 +1029,7 @@ class nsCycleCollector
public:
nsCycleCollector();
~nsCycleCollector();
virtual ~nsCycleCollector();
void RegisterJSRuntime(CycleCollectedJSRuntime *aJSRuntime);
void ForgetJSRuntime();
@ -1079,6 +1081,8 @@ private:
void CleanupAfterCollection();
};
NS_IMPL_ISUPPORTS1(nsCycleCollector, nsISupports)
/**
* GraphWalker is templatized over a Visitor class that must provide
* the following two methods:
@ -1116,7 +1120,7 @@ public:
////////////////////////////////////////////////////////////////////////
struct CollectorData {
nsCycleCollector* mCollector;
nsRefPtr<nsCycleCollector> mCollector;
CycleCollectedJSRuntime* mRuntime;
};
@ -3101,12 +3105,11 @@ nsCycleCollector_startup()
MOZ_CRASH();
}
nsAutoPtr<nsCycleCollector> collector(new nsCycleCollector());
nsAutoPtr<CollectorData> data(new CollectorData);
CollectorData* data = new CollectorData;
data->mCollector = new nsCycleCollector();
data->mRuntime = nullptr;
data->mCollector = collector.forget();
sCollectorData.set(data.forget());
sCollectorData.set(data);
}
void
@ -3210,7 +3213,6 @@ nsCycleCollector_shutdown()
MOZ_ASSERT(data->mCollector);
PROFILER_LABEL("CC", "nsCycleCollector_shutdown");
data->mCollector->Shutdown();
delete data->mCollector;
data->mCollector = nullptr;
if (!data->mRuntime) {
delete data;