Skip to content

Instantly share code, notes, and snippets.

@ilann
Created October 23, 2012 16:00
Show Gist options
  • Save ilann/3939658 to your computer and use it in GitHub Desktop.
Save ilann/3939658 to your computer and use it in GitHub Desktop.
iframe memory leak demo
<!doctype html>
<html>
<head>
<script>
window.SAR = {
alive : true
};
</script>
</head>
<body>iframe </body>
</html>
<!doctype html>
<html>
<head>
</head>
<body>
<h2>Parent</h2>
<div>
<button id="btn_killer">kill iframe</button>
<button id="btn_test">test!</button>
</div>
<iframe id="iframe1" src="if.html" ></iframe>
<script>
var iframe = document.getElementById("iframe1");
var parent_ref_keeper = "NOT SET YET!" ;
iframe.onload = function(){
console.log ("iframe loaded");
parent_ref_keeper = iframe.contentWindow.SAR;
console.log ("parent_ref_keeper set to = " , parent_ref_keeper);
};
window.onload = function (){
var btn_killer = document.getElementById("btn_killer").addEventListener("click" , function(){
document.body.removeChild(iframe);
});
var btn_test = document.getElementById("btn_test").addEventListener("click" , function(){
console.log ("btn_test" , parent_ref_keeper);
});
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment