Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

javascript - iOS7 webkit crashes frequently - not freeing up memory?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...