diff --git a/gfx/layers/ipc/ShadowLayers.cpp b/gfx/layers/ipc/ShadowLayers.cpp index 983e3cd875ee..88baeb22afd6 100644 --- a/gfx/layers/ipc/ShadowLayers.cpp +++ b/gfx/layers/ipc/ShadowLayers.cpp @@ -192,6 +192,21 @@ ShadowLayerForwarder::ShadowLayerForwarder(ClientLayerManager* aClientLayerManag mActiveResourceTracker = MakeUnique(1000, "CompositableForwarder"); } +template +struct ReleaseOnMainThreadTask : public Runnable +{ + UniquePtr mObj; + + explicit ReleaseOnMainThreadTask(UniquePtr& aObj) + : mObj(Move(aObj)) + {} + + NS_IMETHOD Run() override { + mObj = nullptr; + return NS_OK; + } +}; + ShadowLayerForwarder::~ShadowLayerForwarder() { MOZ_ASSERT(mTxn->Finished(), "unfinished transaction?"); @@ -200,6 +215,10 @@ ShadowLayerForwarder::~ShadowLayerForwarder() mShadowManager->SetForwarder(nullptr); mShadowManager->Destroy(); } + if (!NS_IsMainThread()) { + NS_DispatchToMainThread( + new ReleaseOnMainThreadTask(mActiveResourceTracker)); + } } void