Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript constructs/patterns to avoid on iOS Safari?

I have a web app that contains a huge amount of generated JavaScript. The memory consumption differs by a factor 6 between running the web app in Chrome on a Desktop compared to running the web app in a UIWebView on an (updated) iPad.

What constructs or patterns should I avoid to get the memory consumption on iOS on par with that of Chrome?

Characterisation of the generated JavaScript:

  • The code is generated by Haxe.
  • The code is "object oriented" in that it makes heavy use of prototype, but in a civilized way.
  • The code makes heavy use of named indexes on JavaScript objects to implement hash tables.
  • There are a lot of strings, but hardly any string concatenations.

There does not appear to be any memory leaks; the excessive memory consumption on iOS shows immediately upon construction of the (fixed set of) Javascript objects.

like image 553
jpsecher Avatar asked Aug 19 '15 14:08

jpsecher


1 Answers

Since your code does run well on the desktop it is probably some underlying quirk in iOS. Which I doubt you can fix using a more object oriented way of programming. Sure this might reduce the memory footprint a bit but not by a factor of 6.

UIWebView is quite notorious for creating memory leaks you could try to use the newer (iOS 8+) WKWebView has much better garbage collection.

Apple WKWebView Reference

like image 102
Niels Avatar answered Oct 02 '22 10:10

Niels