Bug 1432901 - Part 12: Break cycles manually during shutdown r=yulia

Since mozJSComponentLoader is destroyed after the cycle collector, we need to
break cycles manually before the final cycle collection otherwise we get a
memory leak. Unload() is called at an appropriate earlier point in shutdown.

Differential Revision: https://phabricator.services.mozilla.com/D145567
This commit is contained in:
Jon Coppeard 2022-05-10 12:58:10 +00:00
Родитель aed536664b
Коммит 10fc79714b
3 изменённых файлов: 16 добавлений и 0 удалений

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

@ -873,6 +873,14 @@ ModuleLoaderBase::~ModuleLoaderBase() {
LOG(("ModuleLoaderBase::~ModuleLoaderBase %p", this));
}
void ModuleLoaderBase::Shutdown() {
MOZ_ASSERT(mFetchingModules.IsEmpty());
mFetchedModules.Clear();
mGlobalObject = nullptr;
mEventTarget = nullptr;
mLoader = nullptr;
}
bool ModuleLoaderBase::HasPendingDynamicImports() const {
return !mDynamicImportRequests.isEmpty();
}

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

@ -180,6 +180,9 @@ class ModuleLoaderBase : public nsISupports {
nsISerialEventTarget* aEventTarget =
mozilla::GetMainThreadSerialEventTarget());
// Called to break cycles during shutdown to prevent memory leaks.
void Shutdown();
using LoadedScript = JS::loader::LoadedScript;
using ScriptFetchOptions = JS::loader::ScriptFetchOptions;
using ScriptLoadRequest = JS::loader::ScriptLoadRequest;

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

@ -475,6 +475,11 @@ void mozJSComponentLoader::InitStatics() {
void mozJSComponentLoader::Unload() {
if (sSelf) {
sSelf->UnloadModules();
if (sSelf->mModuleLoader) {
sSelf->mModuleLoader->Shutdown();
sSelf->mModuleLoader = nullptr;
}
}
}