Bug 20315 - Memory leak with Canvas getImageData
Summary: Memory leak with Canvas getImageData
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac OS X 10.5
: P2 Normal
Assignee: Oliver Hunt
URL: http://www.cuppadev.co.uk/assets/canv...
Keywords:
Depends on:
Blocks:
 
Reported: 2008-08-07 02:06 PDT by James Urquhart
Modified: 2008-10-01 22:02 PDT (History)
1 user (show)

See Also:


Attachments
Fixeration (14.28 KB, patch)
2008-10-01 21:41 PDT, Oliver Hunt
mjs: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description James Urquhart 2008-08-07 02:06:39 PDT
I seem to be getting a rather predictable memory "leak" when using getImageData() on a 2d Canvas Rendering Context.

Basically in my test case, i am calling putImageData(getImageData(...), ...) every chance i can get. Memory usage climbs well into the 1 <-> 2gb range.

It should be noted that this occurs in other browsers too, though with varying cut-off points (presumably when the garbage collection finally kicks in).

However it should also be noted that i am essentially running the same code in a real app, i don't seem to encounter this issue (in WebKit r35620). For reference, i have put a copy of this up at the following URL:

http://www.cuppadev.co.uk/hiscumm/webkit-canvas-mem/js_test.html

(search for "fastPaletteRemap" if you want the meat of it)

As for why this is, i am really stumped. So i can't really rely on it.

Any insight would be appreciated of course. :)
Comment 1 Eric Seidel (no email) 2008-09-30 20:41:27 PDT
Ouch.
Comment 2 Geoffrey Garen 2008-09-30 20:44:44 PDT
JSImageData::JSImageData just needs to call JSC::Heap::reportExtraCost.
Comment 3 Oliver Hunt 2008-09-30 21:41:46 PDT
JSCanvasPixelArrayCustom already does that -- i suppose if you never used the CPA that would achieve this result but, if you ever did touch it it would report...

Hmmmm -- i wonder if we ever get rid of the cached wrapper though?
Comment 4 Oliver Hunt 2008-10-01 21:41:30 PDT
Created attachment 24004 [details]
Fixeration

Fix
Comment 5 Maciej Stachowiak 2008-10-01 21:43:02 PDT
Comment on attachment 24004 [details]
Fixeration

r=me
Comment 6 Oliver Hunt 2008-10-01 22:02:54 PDT
Committing to http://svn.webkit.org/repository/webkit/trunk ...
	D	WebCore/bindings/js/JSCanvasPixelArrayCustom.cpp
	M	WebCore/ChangeLog
	M	WebCore/WebCore.xcodeproj/project.pbxproj
	A	WebCore/bindings/js/JSImageDataCustom.cpp
	M	WebCore/bindings/scripts/CodeGeneratorJS.pm
	M	WebCore/html/CanvasPixelArray.idl
	M	WebCore/html/ImageData.idl
Committed r37181