Xhr requests cause high memory usage

173 views
Skip to first unread message

flies

unread,
Oct 14, 2010, 7:49:55 AM10/14/10
to Chromium-extensions
I'm developing the extension that requests certain page from Facebook
at specified interval. After about the 20 minutes the memory usage
rises very high. I isolated the problem to the ajax call causing it
and checked it in simple extension that doesn't parse data or
anything, just makes request. The problem still exists.

Anyone sees if there could be somewhere a memory leak? I suppose that
chrome just keeps the loaded data somewhere in memory and don't
release them. (i've also tried launching this code with the newest
jQuery ( $.get(); ), but the problem is the same. Anyone can help?


function read()
{
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function()
{
if (xhr.readyState == 4)
{
setTimeout(read, 5000);
}
}
xhr.open("GET", 'http://www.facebook.com/reqs.php', true);
xhr.send();
}

read();

PhistucK

unread,
Oct 16, 2010, 10:20:23 AM10/16/10
to flies, Chromium-extensions
I can see what this is happening, not sure V8 should not be optimized to accommodate for these situations, but I can see why this is tricky.
You allegedly created a private variable inside the read function, but you added an event listener to it, that uses as if it is a global variable, which actually makes it as global variable (I think). The garbage collection does not work, maybe because it is an asynchronous object. Maybe if you used the event object to instead of "xhr", there would be less leakage.

On the other hand, when I tried this snippet -
function read() { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { setTimeout(read, 5000); xhr = null; delete xhr;}; } xhr.open("GET", 'http://www.facebook.com/reqs.php', true); xhr.send(); } read();
It did not help, the memory kept on growing.

Search crbug.com for an existing issue and star it. If you cannot find one, file a new issue at new.crbug.com.

Thank you.

PhistucK




--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


Gildas

unread,
Oct 17, 2010, 6:58:19 AM10/17/10
to Chromium-extensions
@flies : The same bug is reported here : crbug.com/52411 but is
unconfirmed (I also see this bug in SingleFile)

@PhistucK : "You allegedly created a private variable inside the read
function, but you added an event listener to it, that uses as if it is
a global variable, which actually makes it as global variable (I
think)"
FYI, It's not a global variable but a closure.

PhistucK

unread,
Oct 17, 2010, 7:35:57 AM10/17/10
to Gildas, Chromium-extensions
Thank you, I am not familiar enough with the terms.
I confirmed the issue, hopefully it will get triaged soon.


PhistucK




--

flies

unread,
Oct 19, 2010, 5:36:43 AM10/19/10
to Chromium-extensions
@Gildas: thanks for the information - I missed this bug report. Hope
it will be figured out soon.

@PhistucK: thanks for the try
Reply all
Reply to author
Forward
0 new messages