Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome extension memory leak in chrome.extension.sendMessage()?

I'm seeing fairly massive memory leaks in long-lived pages using Chrome's chrome.extension.sendMessage()

After sending ~200k events from the Content-Script to the Background-Page as a test, chrome.Event's retained size is ~80% of the retained memory in ~50MB heap snapshot

I've been trying to track down any mistakes I might be making, closing over some variable and preventing it from being GC'd, but it seems to be related to the implementation of Chrome's eventing system

Has anyone run into anything like this, or seen memory leaks with extremely long-lived extensions with Content-Scripts that chatter a lot with a bg page?

The code on my Content-Script side:

  csToBg = function(message) {
    var csToBgResponseHandler = function(response) {
      console.log("Got a response from bg");
      };

    var result = chrome.extension.sendMessage(null, message, csToBgResponseHandler)
  };

And on the Background-Page side, a simple ACK function (to superstitiously avoid https://code.google.com/p/chromium/issues/detail?id=114738):

var handleIncomingCSMessage = function(message, sender, sendResponse) {
  var response = message;
  response.acked = "ACK";

  window.console.log("Got a message, ACKing to CS")

  sendResponse(response);
}

After sending ~200k messages in Chrome 23.0.1271.97 this way, the heap snapshot looks like: heap snapshot

The memory never seems to get reclaimed for the life of the page, and I'm stumped about how to fix it.

EDIT: This is a standard background page, and is not an event page.

like image 550
sgrove Avatar asked Dec 15 '12 21:12

sgrove


1 Answers

This is probably fixed in chrome 32.

Finally!

see http://code.google.com/p/chromium/issues/detail?id=311665 for details

like image 90
luksch Avatar answered Sep 30 '22 11:09

luksch