Hi,
There is a memory leak when rendering images in chrome.
When this memory leak occurs and popup window is closed my extension
ends up with un-releasable memory.
Below is my test harness to reproduce memory leak. I was running
chrome with --purge-memory-button switch.
Background page has to be present and can be empty:
popup.html:
<html>
<head>
<script type="text/javascript">
function onLoad() {
var sourceImg = document.getElementById("myImg");
var div = document.getElementById("myDiv");
var dataUrl = getBase64Image(sourceImg);
for (var i = 0; i < 20; i++) {
var image = document.createElement("img");
console.log("about to give dataurl");
image.src = dataUrl;
image.height = 50;
console.log("appending img");
div.appendChild(image);
setInterval(updateDataUrl, 400, image, dataUrl);
}
}
function updateDataUrl(image, dataUrl) {
var replacementIndex = 1000 + Math.floor(Math.random() * 3000);
image.src = dataUrl.substring(0, replacementIndex) + "1" +
dataUrl.substring(replacementIndex + 1);
}
function getBase64Image(img) {
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
return canvas.toDataURL("image/png");
}
</script>
</head>
<body onload="onLoad()" >
<img id="myImg" src = "
http://beta.clickhint.com/assets/images/blogs/
testPage.png" style="display:none"/>
<div id="myDiv">
</div>
</body>
</html>
To reproduce memory leak just click on popup button and watch task
manager as memory usage grows.
1. Releasing memory: After it reaches let say 100MB click away to
close popup and then purge button. You will see memory nicely
released.
2. Not releasing memory: Same just watch memory growth but instead of
clicking away try to scroll popup. After scrolling window, chrome
won't be able to release this memory !
Same is true for other views. You can try it by running popup in a
tab:
chrome-extension://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/popup.html
Is it possible to release 100% memory from popup after it is closed or
is there a problem with popup and background running in same context?
It is not much of a leak in my case but after a while it accumulates
and can crash extension or browser.
Even enforcing extension reload once every couple of days would be a
temporary solution to me but I am not sure if this is possible.
Thanks,
Marek