diff --git a/content/media/MediaStreamGraph.cpp b/content/media/MediaStreamGraph.cpp index 369d423cf19..f3facb4c428 100644 --- a/content/media/MediaStreamGraph.cpp +++ b/content/media/MediaStreamGraph.cpp @@ -489,10 +489,10 @@ MediaStreamGraphImpl::UpdateStreamOrderForStream(nsTArray* aStack, void MediaStreamGraphImpl::UpdateStreamOrder() { - nsTArray > oldStreams; - oldStreams.SwapElements(mStreams); - for (uint32_t i = 0; i < oldStreams.Length(); ++i) { - MediaStream* stream = oldStreams[i]; + mOldStreams.SwapElements(mStreams); + mStreams.ClearAndRetainStorage(); + for (uint32_t i = 0; i < mOldStreams.Length(); ++i) { + MediaStream* stream = mOldStreams[i]; stream->mHasBeenOrdered = false; stream->mIsConsumed = false; stream->mIsOnOrderingStack = false; @@ -504,8 +504,8 @@ MediaStreamGraphImpl::UpdateStreamOrder() } nsAutoTArray stack; - for (uint32_t i = 0; i < oldStreams.Length(); ++i) { - nsRefPtr& s = oldStreams[i]; + for (uint32_t i = 0; i < mOldStreams.Length(); ++i) { + nsRefPtr& s = mOldStreams[i]; if (!s->mAudioOutputs.IsEmpty() || !s->mVideoOutputs.IsEmpty()) { MarkConsumed(s); } diff --git a/content/media/MediaStreamGraphImpl.h b/content/media/MediaStreamGraphImpl.h index 628c1f5525a..4a1f4c8ed47 100644 --- a/content/media/MediaStreamGraphImpl.h +++ b/content/media/MediaStreamGraphImpl.h @@ -370,6 +370,11 @@ public: // is not running and this state can be used from the main thread. nsTArray > mStreams; + /** + * mOldStreams is used as temporary storage for streams when computing the + * order in which we compute them. + */ + nsTArray > mOldStreams; /** * The current graph time for the current iteration of the RunThread control * loop. diff --git a/xpcom/glue/nsTArray.h b/xpcom/glue/nsTArray.h index 06a6ae64f3a..3a386477005 100644 --- a/xpcom/glue/nsTArray.h +++ b/xpcom/glue/nsTArray.h @@ -1042,6 +1042,20 @@ public: // // Mutation methods // + // This method call the destructor on each element of the array, empties it, + // but does not shrink the array's capacity. + // + // Make sure to call Compact() if needed to avoid keeping a huge array + // around. + void ClearAndRetainStorage() { + if (base_type::mHdr == EmptyHdr()) { + return; + } + + DestructRange(0, Length()); + base_type::mHdr->mLength = 0; + } + // This method replaces a range of elements in this array. // @param start The starting index of the elements to replace.