मैं जेएसओएनपी विकास के लिए नया हूं और मुझे पता चला है कि आईई 7/8 जेएसओएनपी स्क्रिप्ट की याददाश्त को साफ नहीं करेगा। इससे कुछ घंटों के बाद मेरे पृष्ठ में बहुत अधिक मेमोरी खपत होती है।इंटरनेट एक्सप्लोरर में JSONP मेमोरी को कैसे साफ़ करें
मैंने इंटरनेट के चारों ओर देखा और पाया कि अधिकांश फिक्स Neil Fraser से टिप पर आधारित हैं। ब्लॉग से यह और कहा जाता है कि आप की तरह
var tmp;
while (tmp = document.getElementById('JSONP')) {
tmp.parentNode.removeChild(tmp);
// this deletion will create error in IE.
for (var prop in tmp) delete tmp[prop];
tmp = null;
}
कोड का उपयोग कर दुर्भाग्य से हटाए जाने के IE में "ऑब्जेक्ट इस कार्रवाई का समर्थन नहीं करता" की त्रुटि बना दिया जाएगा, लिपि में सभी गुण हटाने की आवश्यकता यह मुफ़्त नहीं होगा यादाश्त।
तो मेरा सवाल यह है कि वास्तव में मेरी JSONP स्क्रिप्ट की स्मृति को कैसे मुक्त किया जाए?
मैं नीचे के रूप में मेरे परीक्षण कोड डाल:
Testing.html
<html><head></head><body><script>
var script,
head = document.getElementsByTagName('head')[0],
loadCount= 0,
uuid= 1,
URL= "memleaktest.js?uuid=",
clearConsole = function() {
var con= document.getElementById("console");
while (con.childNodes.length)
con.removeChild(con.childNodes[0]);
},
log = function(msg) {
var div= document.createElement("DIV"),
text= document.createTextNode(msg),
con= document.getElementById("console");
div.appendChild(text);
con.appendChild(div);
},
test = { "msg" : null, "data" : null };
var loaded= function() {
if (!test.msg)
return setTimeout(loaded,10);
log("loaded #" + loadCount + ": " + test.msg);
var tmp;
while (tmp = document.getElementById('JSONP')) {
tmp.parentNode.removeChild(tmp);
// not working in IE 7/8
// for (var prop in tmp) delete tmp[prop];
tmp = null;
}
test.msg = test.data = null;
if (--loadCount)
setTimeout(load, 100);
};
var load = function(){
var url= URL + (uuid ++);
log("load via JSONP: "+url);
script= document.createElement('script');
script.id = 'JSONP';
script.type = 'text/javascript';
script.charset = 'utf-8';
script.src = url;
head.appendChild(script);
setTimeout(loaded,1000);
};
</script>
<div>
<button onclick="loadCount=3; load();" name="asd" value="asdas">jsonp load</button>
<button onclick="clearConsole();" name="asd" value="asdas">clear Console</button>
</div>
<div id="console"></div>
</body></html>
memoryleaktest.js
test.msg = "loaded #"+loadCount;
test.data = "test data with 1MB size";
आप दो फ़ाइलों में कोड चिपकाकर द्वारा स्मृति रिसाव को पुन: कर सकते हैं और Testing.html खोलें।
मैंने लीक को ट्रैक करने के लिए ड्रिप का उपयोग किया और ड्रिप में आप देख सकते हैं कि स्मृति बढ़ती जा रही है और "<" स्क्रिप्ट ">" हटाई नहीं गई है।
किसी भी मदद के लिए बहुत बहुत धन्यवाद!
ग्रेट पहला प्रश्न। एसओ में आपका स्वागत है –