mercredi 31 décembre 2014

Why does Instruments say that WebKit in iOS (Safari) is allocating 200 MB of ram when I request a 15 MB file?


I am helping develop a cross platform web app, and we want to store about 20MB of data on the client. We are using the Application Cache to store our HTML, CSS, and JavaScript, and we are using the WebSQLDB to store other data. This has been causing crashes on the iPad 2 because it runs out of memory.


I narrowed it down to the 15MB file we store in WebSQL. I've been cutting it down to smaller and smaller examples, and noticed that the XML HTTP Request was actually the main culprit. Even with this small example, according to Instruments, about 200 Mb is being allocated in Webkit. And I never get that memory back. If the app keeps doing more stuff and gets up to about 350MB allocated, it will blow up on the iPad 2 every time.


Is this a memory leak in Webkit? Is it just a limitation of the platform? Poor JS implementation? How can I download this file in Safari without risking crashing the browser?



<!DOCTYPE html>
<html xmlns="http://ift.tt/lH0Osb">
<head>
<title>test</title>

<script>

(function (global, undefined) {
"use strict";


global.xhrObj = new window.XMLHttpRequest();

global.xhrObj.onreadystatechange = function () {
if (global.xhrObj.readyState === 4) {
alert('nulling it out');
global.xhrObj = null;
alert('done');
}
};

global.xhrObj.open("GET", "http://ift.tt/14dg0Wh");

global.xhrObj.setRequestHeader("X-Requested-With", "XMLHttpRequest");

global.xhrObj.send();

}(window));

</script>

</head>
<body>
</body>
</html>




Aucun commentaire:

Enregistrer un commentaire