GraphicsContext::restore() uses removeLast() which never nukes the Vector<State>'s backing store. This means that we always have capacity for at least 16 states in each GraphicsContext that has ever save()d. Since canvas elements have a persistent GraphicsContext, this adds up to a bunch of memory with multiple canvases around.
Created attachment 254604 [details] Patch
Comment on attachment 254604 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=254604&action=review r=me > Source/WebCore/platform/graphics/GraphicsContext.cpp:140 > + // Make sure we deallocate the state stack buffer when it goes empty. > + // Canvas elements will immediately save() again, but that goes into inline capacity. > + if (m_stack.isEmpty()) > + m_stack.clear(); Should Vector do this automatically?
To elaborate, I really hate it that std::vector does not do this automatically. At the limit, you have to add a call to clear to every client!
(In reply to comment #3) > To elaborate, I really hate it that std::vector does not do this > automatically. At the limit, you have to add a call to clear to every client! I guess you mean WTF::Vector. We can totes do that. Let's separate the issues though.
> > To elaborate, I really hate it that std::vector does not do this > > automatically. At the limit, you have to add a call to clear to every client! > > I guess you mean WTF::Vector. > We can totes do that. Let's separate the issues though. No, I mean that std::vector never ever shrinks until you call shrink_to_fit, which is super annoying, while WTF::Vector often shrinks automatically, but misses in this case.
Comment on attachment 254604 [details] Patch Clearing flags on attachment: 254604 Committed r185396: <http://trac.webkit.org/changeset/185396>
All reviewed patches have been landed. Closing bug.