开发者

chrome extension memory hog with basic function

I have a chrome extension thats very complex, but I'll simplify the issue which can be reproduced easily.

manifest.json:

{
  "name": "script",
  "version": "1.0",
  "description": "script",
  "browser_action": {
    "default_icon": "icon.jpg"
  },
  "permissions": [
    "tabs", 
    "http://www.google.com/"
  ],
  "background_page" : "background.html",
  "content_scripts":[
  {
"matches":["http://www.google.com/"],
"js":["/jquery.js","/script.js"]
}

] }

script.js:

var item = null;
restart();
function restart() {
    item = null;
    item = new Object();
    item.Go = Go;
    item.Go();
}

function Go() {
    setTimeout(function () { restart(); }, 5);
}

background.html:does nothing for now

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script src="http://code.jquery.com/jquery-1.4.2.min.js" language="javascript" type="text/javascript"></script>
</head>
<body>
</body>
</html>

Now, when what my project is supposed to do is very simple...refresh a page, scrape data, post the results to a local jsonp web service, repeat. I'm having an issue with the chrome tab and the exte开发者_开发问答nsion hogging memory, which can be viewed by pressing SHIFT+ESC in chrome. Run the above extension for chrome and you can slowly see the page size constantly increase in size. With the example above you can see that the tab increases but the extension memory usage does not increase until things get a bit more difficult.

Why does the memory usage increase constantly when the only thing going on is an item being created then nullified over and over again? Shouldn't that clear the object from memory?


This might not be an amazingly big issue, Chrome/V8 can choose when to run the Garbage collector, so it might not be running when you expect it too. You are instantiating an object in an object that might not be getting released.

The easiest way to check what is happening, is to open your background page in the debugger, click the profiles tab, then click "Heap snapshot" twice, after the 2nd click you will see a report that should indicate that memory has been freed. Essentially you are forcing a Garbage collection to happen. See attached screenshot.

chrome extension memory hog with basic function

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜