Chrome memory leak on popup affects background page.

246 views
Skip to first unread message

marek chovanec

unread,
Dec 1, 2010, 11:29:17 AM12/1/10
to Chromium-extensions
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

donaddon

unread,
Dec 3, 2010, 10:26:21 AM12/3/10
to Chromium-extensions
This memory leak has been around for a good while. I believe it's a
webkit issue in general, please be sure to vote on the following
(unfortunately noisy) tickets. The webkit bug has a nice succinct
repro for easily crashing Safari or Chrome (last I checked):

Webkit: https://bugs.webkit.org/show_bug.cgi?id=23372
Chrome: http://code.google.com/p/chromium/issues/detail?id=36142
Reply all
Reply to author
Forward
0 new messages