Home >Web Front-end >JS Tutorial >jquery does not automatically recycle the xmlHttpRequest object, causing memory overflow_jquery
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: