5

I'm noticing my Phonegap app is having some memory issues on iOS7 that weren't happening on iOS6 .

  1. long iScroll lists with many images
  2. displaying images from the phone's album (9mp) will crash after you view several

For #1, this was never an issue on iOS6, regardless of device.

For #2, I am re-using the same DIV element to display the next picture, so it seems that the previous image is not being cleared.

The techniques mentioned in this post no longer appear to work in iOS7: iPad/iPhone browser crashing when loading images in Javascript

Community
  • 1
  • 1
Daniel Roizman
  • 141
  • 2
  • 5
  • I am experiencing a similar problem. My application which ran fine on iOS 6 now also crashes in iOS 7.0.3 because the image memory is not properly disposed. I am using a similar techniques to the one described in your link. Did you find out anything new about it? Did you file a bug already? – Mark Nov 04 '13 at 14:45

1 Answers1

3

The best solution for this problem I found is the following code:

var img = document.getElementById('imageID');
img.parentNode.removeChild(img);
img.src = 'data:image/gif;base64,' + 
      'R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=';
setTimeout(function() {
img = null;
}, 60000);

This sets the src attribute to a tiny gif and then waits long enough for garbage collection to happen eventually.

See: http://www.fngtps.com/2010/mobile-safari-image-resource-limit-workaround/

This should work for you. I could verify that the memory is released by using the Xcode instruments. Unfortunately this solution doesn't seem to work for homescreen apps which I am using.

Mark
  • 3,389
  • 2
  • 28
  • 52
  • 7.0.4 experiences the same issue. We are using phonegap + backbone + rivets. I did this on close of each view, it helped a tiny bit. Going to try to implement this in data binding of rivets too, but that's the last place i know of that could help. – Krym Nov 19 '13 at 08:42
  • My issues seem to be fixed in iOS 7.0.4. There is also a 7.1 beta out today. – Mark Nov 19 '13 at 10:46
  • you mean this is not applicable to ios 7+ ? – jujule Aug 31 '15 at 00:49
  • Last time I checked not. Do you have this problem? – Mark Aug 31 '15 at 16:03