Fatal image loading bug in iPhone 2.x

1 view
Skip to first unread message

wayne

unread,
Oct 26, 2008, 12:12:39 PM10/26/08
to iPhoneWebDev
While iPhone 2.x has provided great improvements (e.g. Safari multi-
touch interface, SQL database, full screen web apps), there were
persistent reports about strange crashes, malfunctions and
instabilities in Safari and in native apps. While tracking down
problems reported by some of our users, I have found the root of the
problems -- broken garbage collection in Safari (desktop and mobile)
in combination with severe limitation (~4.5 MB of png/jpeg data) on
total image data.

It seems that Safari never releases memory for inaccessible/released
images, as they get replaced with new images (e.g. via change in
img.src or via creation of new Image() elements overwriting the same
img variable). In the desktop Safari one can observe continued
increase in the memory footprint as you replace old image with new
image, until it uses up entire system memory and crashes. In the
mobile Safari the problem is far more serious, since the mobile Safari
simply stops loading new images after about 4.5MB of png or jpeg image
data was loaded. What is even worse, the mobile Safari ceases to issue
either load, error or abort events so your code doesn't even know
there is a problem. Of course, user sees the problem since the picture
on the screen freezes.

I made a little bare bones slide show, which simply loads new pictures
(via replacement of img.src of a displayed image element, see the
source), illustrating the problem on iPhone 2.x Safari:

http://www.myf2p.com/test/slideshow.htm

After loading 9 images (out of 12), each using ~460k, the image
loading and all loading events quietly stop. Desktop Safari or iPhone
1.x (or other browsers) will load all 12 images. Note that it is
essential for the problem that images are distinct (Safari apparently
recognizes identical images and doesn't increase the memory footprint
in that case). The problem reproduces on iPhone 2.x every time (you
can also vary how you create or load new image; even using
XMLHttpRequest to load image as data URI has the same problem). In
contrast, iPhone 1.x will run such slide show with distinct images
indefinitely. The current desktop Safari 3.1 will show distinct images
until it runs out of system memory (having never reclaimed any memory
for released images). If you were to repeat this test on iPhone 2.x
with each run serving a new set of 9 images (different from previous
images; this needs server side code which is not included in the
sample above), the Safari will crash when the total image data (png or
jpeg) over multiple runs reaches ~30MB (i.e. after repeating the above
test ~7 times).

Jorge Chamorro

unread,
Oct 26, 2008, 2:00:35 PM10/26/08
to iphone...@googlegroups.com
Hmm, that's true... :-(

--
Jorge.

Creed Erickson

unread,
Oct 26, 2008, 1:18:00 PM10/26/08
to iphone...@googlegroups.com
So, have you filed a bug report with Apple? I believe you can do so on their developer site with your ADC Online ID (free membership.) http://developer.apple.com/bugreporter/

Michael Kaye

unread,
Oct 26, 2008, 2:10:47 PM10/26/08
to iphone...@googlegroups.com
Known bug and appears when using UIWebview natively...hopefully it
will be fixed soon...but worth reporting anyway as the more time
reported the better imho.

wayne

unread,
Oct 26, 2008, 4:27:59 PM10/26/08
to iPhoneWebDev
On Oct 26, 12:18 pm, "Creed Erickson" <creed.erick...@gmail.com>
wrote:
> So, have you filed a bug report with Apple? I believe you can do so on their
> developer site with your ADC Online ID (free membership.)http://developer.apple.com/bugreporter/

Yep, I reported this version few days ago. The mobile Safari crashing
(which is a compounded version of this one) was reported couple months
ago. They responded that it was memory use exceeding some limit and
that was the end of that. There was nothing I could fix in my code,
though, since I was releasing unused images and it was Safari garbage
collector that failed to free the inaccessible image memory. Perhaps
2.2 will have a fix for these problems. Has anyone tried it on 2.2
sdk? (2.1 simulator has the same problem)

wayne

unread,
Oct 27, 2008, 11:03:05 AM10/27/08
to iPhoneWebDev
On Oct 26, 1:10 pm, Michael Kaye <michaelk...@mac.com> wrote:
> Known bug and appears when using UIWebview natively...hopefully it
> will be fixed soon...but worth reporting anyway as the more time
> reported the better imho.
>

That's unfortunate since I had just started transferring our web app
into native mode, intending in the first pass to use UIWebView to get
around this very problem (the image load failure at ~4.5MB of image
data and subsequent Safari crashes at ~30MB accumulation).

Do you know whether they have fixed it in the upcoming OS 2.2?

wayne

unread,
Oct 27, 2008, 11:39:53 AM10/27/08
to iPhoneWebDev
On Oct 26, 1:10 pm, Michael Kaye <michaelk...@mac.com> wrote:
> Known bug and appears when using UIWebview natively...hopefully it
> will be fixed soon...but worth reporting anyway as the more time
> reported the better imho.
>

A bit of good news:

I just checked our server logs and there is an access to the slideshow
file
from iPhone mobile Safari, OS 2.2, which makes it through all 12
slides
(all other iPhone accesses fail after 9 slides). The User Agent string
for
this successful access is:

Mozilla/5.0+(iPhone;+U;+CPU+iPhone+OS+2_2+like+Mac+OS+X;+fi-fi)+
AppleWebKit/525.18.1+(KHTML,+like+Gecko)+Version/3.1.1+
Mobile/5G62+Safari/525.20

Does anyone who has beta OS 2.2 recognize this Safari version?

Michael Kaye

unread,
Oct 27, 2008, 1:13:42 PM10/27/08
to iphone...@googlegroups.com
That is good news. Haven't installed 2.2 yet because have an iPhone
app waiting on release....but look forward to trying UIWebView with
2.2 soon.

Thanks & regards, Michael.

Reply all
Reply to author
Forward
0 new messages