[ACCEPTED]-Iframes and memory management in Javascript-iframe
Accepted answer
In the iframe, trigger a reload before removing 3 it and then remove it.
<a href="#">Remove</a>
<iframe src="url" />
$('a').click(function(){
$('iframe')[0].contentWindow.location.reload();
setTimeout(function(){
$('iframe').remove();
}, 1000);
});
Addionally, you can 2 do a manual cleaning up too - i.e. if you 1 have data in your cookies or HTML5 localStorage.
window.onbeforeunload = function(){
$(document).unbind().die(); //remove listeners on document
$(document).find('*').unbind().die(); //remove listeners on all nodes
//clean up cookies
/remove items from localStorage
}
If any objects from the iframe is referenced 4 in a object in the main window that object 3 won't be removed from the DOM, so, if you 2 have something like this:
Main window:
var object = {};
function iframe_call(data){
object.iframe_data = data.something
}
iframe:
function onClick(){
parent_object.iframe_call(this);
}
this 1 happens especially if you refer DOM objects.
var frame = document.getElementById("myframe");
frame.src = "about:blank";
This worked from me and prevented memory 3 leaks. Ig you must destroy the parent of 2 the iframe, do it with some delay to prevent 1 memory leak
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.