简体   繁体   English

Internet Explorer内存泄漏

[英]Internet Explorer memory leaks

I have a webapp written in react that sends ajax requests to receive chunks of 5 pages of a document. 我有一个用react编写的webapp,它发送ajax请求来接收5页文档的块。 For this the request itself calls its function recursively as a timeout to receive the next 5 pages. 为此,请求本身以递归方式调用其函数作为超时以接收接下来的5个页面。

Additional info: I use the official flux from the npm repositories. 附加信息:我使用来自npm存储库的官方流量。 Following code example: 以下代码示例:

function getPages() {

    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (this.readyState === 4 && this.status === 200) {
            var resp = JSON.parse(this.responseText);
            SwitchViewAction.addPages(resp); // calls another setTimeout later,
                                             // because of react lifecycle

            if (Object.keys(resp).length > 0) {
                setTimeout(getPages(), 0);
            }
        }
    };

    xhttp.open("GET", '/GetDocumentPages/', true);
    xhttp.send();
}

The problem is, that IE 11 allocates nearly ~20MB memory for each request (or timeout?). 问题是,IE 11为每个请求(或超时?)分配了近20MB的内存。 If I render a document with ~250 pages, IE runs out of memory and I get the following error: 如果我渲染一个约250页的文档,IE内存不足,我收到以下错误:

Not enough storage is available to complete this operation.

I found this page , that explains that setTimeout sets an internal reference so the timeout is never deleted. 我找到了这个页面 ,它解释了setTimeout设置了一个内部引用,因此永远不会删除超时。 But only for IE <9. 但仅适用于IE <9。 So in 11 this problem should not be. 所以在11这个问题不应该。

Chrome handles this perfectly. Chrome处理完美。 The maximum amount of memory usage is ~170MB for this huge document. 对于这个巨大的文档,最大内存使用量约为170MB。 IE runs over 1GB and returns the above error on the console. IE运行超过1GB并在控制台上返回上述错误。 Later in the code I add "resp" to an array. 稍后在代码中我将“resp”添加到数组中。 If I do not add it, IE stays at ~220MB memory usage. 如果我不添加它,IE保持在~220MB内存使用。 So imho there must be a reference problem. 所以我必须有一个参考问题。

Further information: The document pages are sent as base64. 更多信息:文档页面以base64格式发送。 I calculated the maximum size, when all pages are received. 收到所有页面后,我计算了最大尺寸。 It is ~162MB for the document with 249 pages. 这个文件有大约162MB,有249页。

Is this a problem with IE handling the references, is it IE to not free memory, or am I on a completely wrong track? 这是一个IE处理引用的问题,是IE不能释放内存,还是我完全错误的轨道? So what could it be then? 那么它会是什么呢?

The timeout syntax is not correct, you should call it like this: 超时语法不正确,您应该这样调用它:

setTimeout(getPages, 0);

Otherwise you call the function right away, and indeed would run out of memory as the state of previous function calls never get garbage collected. 否则你立即调用该函数,并且由于先前函数调用的状态永远不会被垃圾收集,实际上会耗尽内存。

The problem is that IE wastes memory while rendering base64 strings as images. 问题是IE在将base64字符串渲染为图像时浪费了内存。 The solution for me is to render only a bunch of pages and not the entire document. 对我来说,解决方案是只渲染一堆页面而不是整个文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM