Is there a way to prevent XHR POST Memory leak in my web app? I have searched extensively for solutions but have not found any satisfactory answers. My issue is similar to the one described in this blog post that outlines the problem without offering any fixes.
My Dilemma: I am continuously sending large amounts of data (2Mb to 80Mb) to the server through POST requests, ranging from 10 to 300 requests. This problem does not occur with GET requests.
What can I do to resolve this? I have tried addressing circular references, scopes, closures, and more without success. Attempting to use the delete keyword during readystate changes, deleting previous XHR objects, reusing XHR objects, setting XHR references to null, and altering coding patterns all have not yielded positive results.
Below is a sample code illustrating the functionality I require:
var base_string = "ABCDEFGHIJKLMNOPQUST01234567890!@#$%^&:ABCDEFGHIJKLMNOPQUST01234567890!@#$%^&ABCDEFGHIJKLMNOPQUST01234567890!@#$%^&";
base_string += base_string;
base_string += base_string;
base_string += base_string;
base_string += base_string;
base_string += base_string;
base_string += base_string;
base_string += base_string;
base_string += base_string;
base_string += base_string;
base_string += base_string;
base_string += base_string;
base_string += base_string;
base_string += base_string;
base_string += base_string;
base_string += base_string;
base_string += base_string;
base_string += base_string;
this.sampleData = base_string;
var dataToSend = this.sampleData.substring(0, 2000000);
this.xhr = [];
this.xhr[0] = new XMLHttpRequest();
function sendRequest (){
var Self = this;
Self.xhr[0].onload = function (test) {
sendRequest ();
};
Self.xhr[0].open("POST", "http://localhost/upload.php" + "?n=" + Math.random(), true);
Self.xhr[0].send(dataToSend);
}
sendRequest ();
How can I achieve this functionality without encountering memory leaks?