Memory leak in Chrome using shared desktop?

I have a webpage that runs an HTML5 SharedWorker script. Chrome memory usage increases every time this page reloads (pressing F5).

The working script is very simple. Every second (using setInterval ) a message is sent to the connected port.

It seems like the workflow is completing and restarting every time I press F5. This is what I expect, because in reality the employee is not shared by more than one “document”. However, I cannot understand why the memory usage is increasing with every update.

Does anyone know why this is happening?

Given that the memory increases every time the page reloads, it seems to me that I can’t use shared users in Chrome at all. Could anyone do this without memory problems?

UPDATE

This is HTML hosting:

 <div id="output"></div> <script type="text/javascript" src="/scripts/jquery-1.4.4.js"></script> <script type="text/javascript"> $(function () { var worker = new SharedWorker("/scripts/worker.js") worker.port.onmessage = function(e) { $("#output").append($("<div></div>").text(e.data)); }; worker.port.start(); }); </script> 

... and this is worker.js :

 var list = []; setInterval(function () { for (var i = 0; i < list.length; ++i) { list[i].postMessage("#connections = " + list.length); } }, 1000); onconnect = function (event) { list.push(event.ports[0]); }; 

The hosting page starts / connects to the shared worker and displays everything that is received from it.

The working code stores a list of connected ports and sends a message to all of them once a second.

This is simple stuff. However, every time the hosting page reloads in Chrome. The memory payload for this tab has been increased.

The following shows the use of Chrome memory after several updates:

After refreshing a couple of times I've reached 100 MB

... after the upgrade, I still reach 250 MB ...

Reaching 250 MB after some more refreshing

I'm running out of ideas thinking it's a bug in Chrome. Can someone give me some kind of pointer?

UPDATE 2

Disabling my AdBlock extension seems to fix the problem:

Running without adblock

So, I was a little happy, but it turned out that the memory is still leaking . If AdBlock is disabled, it just runs a little less on page refresh.

+7
source share
2 answers

It seems that the Chromium team has solved this problem. I can no longer reproduce it.

+1
source

First Name your SetInterval myInterval = setInterval ("change ()", 1000);

Then on the "Logout" or "Logout" page, etc.

clearInterval (myInterval); or bind to another stop event ...

Example:

 <script language="JavaScript"> /* Image Preloading */ a = new Image();a.src = "screw.jpg"; b = new Image(); b.src = "washer.jpg"; c = new Image(); c.src = "capnut.jpg"; d = new Image(); d.src = "coffee.gif"; //end image preloading pix = new Array("screw.jpg","washer.jpg","capnut.jpg","coffee.gif"); var i = 0; var counter = 1; function slideshow(){ ImgPreload = setInterval("change()", 1000); } function change(){ document.images.pic.src = pix[i]; i = i + 1; if (i > (pix.length - 1)) {i = 0; counter = counter + 1;} if (counter > 2) {clearInterval(ImgPreload);} } </script> 

Although this is not exactly what you are doing, it is a good resource for such circumstances. Without, clearInterval and your memory usage trigger are automatically cached as basic for webkit ... it tries to help you by loading the appropriate loads from this script as cache elements or something like that.

:)

-3
source

All Articles