Bug 1797688 - Part 6: Substitute gXPCOMThreadsShutDown with InOrBeyond(XPCOMShutdownFinal) in SurfaceCacheImpl. r=xpcom-reviewers,mccr8

To release the images, `ClearReleasingImages` basically takes all the `RefPtr<Image>` out of `mReleasingImagesOnMainThread` under a lock and then clears them, all on the main thread. This can be safely done before as late as XPCOMShutdownFinal on the main thread in order to avoid leaks.

Differential Revision: https://phabricator.services.mozilla.com/D160624
This commit is contained in:
Jens Stutte 2022-11-01 14:08:45 +00:00
parent c9e6f9840c
commit a71d351e3b

View file

@ -19,6 +19,7 @@
#include "gfx2DGlue.h"
#include "gfxPlatform.h"
#include "imgFrame.h"
#include "mozilla/AppShutdown.h"
#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/CheckedInt.h"
@ -1398,7 +1399,8 @@ class SurfaceCacheImpl final : public nsIMemoryReporter {
bool needsDispatch = mReleasingImagesOnMainThread.IsEmpty();
mReleasingImagesOnMainThread.AppendElement(image);
if (!needsDispatch || gXPCOMThreadsShutDown) {
if (!needsDispatch ||
AppShutdown::IsInOrBeyond(ShutdownPhase::XPCOMShutdownFinal)) {
// Either there is already a ongoing task for ClearReleasingImages() or
// it's too late in shutdown to dispatch.
return;
@ -1933,7 +1935,7 @@ void SurfaceCache::ReleaseImageOnMainThread(
// Don't try to dispatch the release after shutdown, we'll just leak the
// runnable.
if (gXPCOMThreadsShutDown) {
if (AppShutdown::IsInOrBeyond(ShutdownPhase::XPCOMShutdownFinal)) {
return;
}