Home > Web Front-end > JS Tutorial > jquery does not automatically recycle the xmlHttpRequest object, causing memory overflow_jquery

jquery does not automatically recycle the xmlHttpRequest object, causing memory overflow_jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 17:52:44
Original
1077 people have browsed it

I have never noticed this before. Fortunately, I read kuibono’s article today. Here is the code snippet given by kuibono to manually recycle the xmlHttpRequest object:
Every Ajax request of jquery will create an xmlHttprequest object. Theoretically, The request for a long connection is an infinite recursion, and the number of requests is very large. However, since each request will create a new xmlhttprequest, and jquery will not automatically recycle resources, it will cause memory overflow.

By looking at the jquery API, I found that jquery also has a complete object, which is a callback function after the request is completed (called after the request is successful or failed). There are two parameters XMLHttpRequest and textStatus at the same time. Therefore, we only need to manually recycle the returned XMLHttprequest object after the request is completed. The code is as follows:

Copy code The code is as follows:

$.ajax({
url: "http://www.jb51.net",
data: { name: "xxxx" },
dataType: "xml",
success: function (data, textStatus) {
//do something...
},
complete: function (XHR, TS) { XHR = null }
});
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template