Bug 134355 - Serious canvas memory leak in iOS 7.1.1.
Summary: Serious canvas memory leak in iOS 7.1.1.
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Canvas (show other bugs)
Version: 528+ (Nightly build)
Hardware: iPhone / iPad iOS 7.0
: P2 Critical
Assignee: Nobody
URL: http://stackoverflow.com/questions/24...
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2014-06-26 12:42 PDT by aga
Modified: 2020-05-21 10:53 PDT (History)
6 users (show)

See Also:


Attachments
Test case (1.06 KB, text/html)
2014-07-20 12:47 PDT, M. Hanselmann
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description aga 2014-06-26 12:42:21 PDT
Not sure if this is an internal iOS issue or not, but in Safari on iOS 7.1.1 there is a serious canvas memory leak:

http://stackoverflow.com/questions/24387541/ios-7-1-1-canvas-drawimage-memory-leak/ :

ctx.drawImage(anotherCanvas, clipX, clipY, clipW, clipH, x, y, w, h) --> memory leak.
ctx.drawImage(anotherCanvas, x, y, w, h) --> no memory leak.
Comment 1 Simon Fraser (smfr) 2014-06-26 17:10:53 PDT
How did you determine that this causes a memory leak?
Comment 2 aga 2014-06-27 20:45:32 PDT
I may have been a bit hasty. This may not be a memory leak... I did find an audio memory leak in my web-app... I think that is the problem... although this might be a problem in and of itself.

https://bugs.webkit.org/show_bug.cgi?id=134425
Comment 3 M. Hanselmann 2014-07-20 12:47:34 PDT
Created attachment 235190 [details]
Test case

A customer of mine reported an issue application using UIWebView. It would become slow and eventually crash after quite some time. I have since investigated the issue and have to confirm the original report. Tests were done using iOS 7.1.2.

If the allocation traces by Instruments.app are to be believed, the leaks is in the vicinity of WebCore/platform/graphics/cg/ImageSourceCG.cpp, but I'm not familiar enough with WebKit/WebCore to be certain. It may also be an issue in Apple prorietary code.

The attached test case can be used to reproduce the issue reliably. The test image was a PNG file with 768×576px. Another test used a file with 981×820px.

I haven't succeeded in getting allocation traces using Mobile Safari, but in a custom application the memory consumption increased at a steady 1.2-1.4 MB per 1'000 frames.
Comment 4 M. Hanselmann 2014-07-27 15:12:36 PDT
Since my last update I did a few more tests using an iPhone 4 running iOS 7.1.2. Here's how to reproduce the issue without Cordova/PhoneGap:

- Put test case HTML on a webserver
- Put image with at least 800×800px as “test.png” on web server (not sure if the size is relevant)
- Create new iOS Single View Application project in Xcode
- Open iOS storyboard
- Add UIWebView element
- Add outlet for web view to ViewController.m
- Add the following code to -[ViewController viewDidLoad] (make sure to use the correct URL):
  [_webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://server:8080/"]]];
- Run program on iPhone and watch its memory usage using Instruments.app

When I look at the allocation summary, the IOAccelResource category keeps increasing at a rate of about 24 KB/sec (measured over 8 minutes after a warm-up period of half a minute). CGImageProvider and CGImage keep allocating memory, too.

Tests with more than one image did not, as far as I could tell, change the numbers in a significant way.

Interestingly this doesn't even seem to be the same issue that I see in my client's application. All I know is that something somewhere is leaking.
Comment 5 Simon Fraser (smfr) 2014-07-27 16:15:27 PDT
(In reply to comment #4)
> Since my last update I did a few more tests using an iPhone 4 running iOS 7.1.2. Here's how to reproduce the issue without Cordova/PhoneGap:
> 
> - Put test case HTML on a webserver
> - Put image with at least 800×800px as “test.png” on web server (not sure if the size is relevant)
> - Create new iOS Single View Application project in Xcode
> - Open iOS storyboard
> - Add UIWebView element
> - Add outlet for web view to ViewController.m
> - Add the following code to -[ViewController viewDidLoad] (make sure to use the correct URL):
>   [_webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://server:8080/"]]];
> - Run program on iPhone and watch its memory usage using Instruments.app
> 
> When I look at the allocation summary, the IOAccelResource category keeps increasing at a rate of about 24 KB/sec (measured over 8 minutes after a warm-up period of half a minute). CGImageProvider and CGImage keep allocating memory, too.
> 
> Tests with more than one image did not, as far as I could tell, change the numbers in a significant way.
> 
> Interestingly this doesn't even seem to be the same issue that I see in my client's application. All I know is that something somewhere is leaking.

If you haven't already, please file a bug a bugreporter.apple.com with a test application that can be run out of the box.

Have you tested any iOS 8 seeds for this bug?
Comment 6 M. Hanselmann 2014-07-27 16:20:27 PDT
(In reply to comment #5)
> If you haven't already, please file a bug a bugreporter.apple.com with a test application that can be run out of the box.

I'm in the process of preparing that, but I wanted to document my discoveries publically. In addition I want to make a minimal example for the exact case we have in my customer's application first.

> Have you tested any iOS 8 seeds for this bug?

Unfortunately not. My only test device is an iPhone 4, which isn't supported by iOS 8.
Comment 7 M. Hanselmann 2014-07-27 20:25:57 PDT
(In reply to comment #5)
> If you haven't already, please file a bug a bugreporter.apple.com with a test application that can be run out of the box.

I have created a report there now. The ID is 17825107.
Comment 8 nicolas.ramz 2015-06-08 17:58:51 PDT
I'm not sure this is related, but I have a piece of code that crashes Safari on iOS 7/8 (crashes the whole app on iOS 7, crashes current tab only on iOS 8): http://experiments.warpdesign.fr/iOSCanvasBug/

It happens when calling ctx.drawImage() using a canvas as source.
Comment 9 Simon Fraser (smfr) 2015-06-08 18:28:59 PDT
Please try the iOS 9 beta.
Comment 10 Jon Lee 2019-06-19 17:20:12 PDT
rdar://problem/17825107