New issue 52411 by Tony.Val...@PowerDNN.com: AJAX Memory Leak - Chrome
Never Releases Memory Consumed by AJAX Unless Tab is Closed
http://code.google.com/p/chromium/issues/detail?id=52411
Chrome Version : 5.0.375.126
URLs (if applicable) : Any URL using Ajax.
http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/DynamicPopulate/DynamicPopulate.aspx
Other browsers tested:
Add OK or FAIL after other browsers where you have tested this issue:
Firefox 3.x: OK
IE 7: OK
IE 8: OK
What steps will reproduce the problem?
1. Go to a website that has AJAX stuff on it such as:
http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/DynamicPopulate/DynamicPopulate.aspx
2. Cause the AJAX code to execute over and over again.
3. You'll see that tab's memory usage go higher and higher and then Chrome
will error out at you. Chrome never releases the memory.
What is the expected result?
Chrome should release memory associated with old AJAX requests.
What happens instead?
Chrome just keeps using more and more memory.
Please provide any additional information below. Attach a screenshot if
possible.
In the screen shot, I'm using a program named Kayako Fusion V4.0 (it is the
latest release of a highly popular Helpdesk program). Kayako Fusion V4.0
is completely AJAX based which is what brought this to my attention. At
first, I thought it may be an issue with Kayako since it is beta software,
however, I tested with IE and FF and I did not get the large memory usage
that I do with Chrome. I then went to other websites that use AJAX and
verified that after repeated actions, Chrome's memory goes higher and
higher and it never appears to release any memory.
Attachments:
Google Chrome.jpg 170 KB
Comment #1 on issue 52411 by phist...@chromium.org: AJAX Memory Leak -
Chrome Never Releases Memory Consumed by AJAX Unless Tab is Closed
http://code.google.com/p/chromium/issues/detail?id=52411
Perhaps not the best reduced test case, but here it is -
function read()
{
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function()
{
if (xhr.readyState == 4)
{
setTimeout(read, 5000);
xhr = null;
delete xhr;};
}
xhr.open("GET", '/', true);
xhr.send();
}
read();
Confirmed on Windows Vista Home Premium SP 2 and Chrome 8.0.552.X dev and
on Windows XP Professional SP 2 and Chrome 8.0.555.0 canary build (both of
them uses the Classic Windows theme).
A real world test could be ComicBookRealm.com. I have noticed that after
using the site for a while with Chrome my computer gets really slow. I
then notice that Chrome is using a lot of memory. This site is primarily
AJAX driven (looks like jQuery). If I switch to FF or even IE I do not
experience the problem.
Comment #5 on issue 52411 by ant...@chromium.org: AJAX Memory Leak - Chrome
Never Releases Memory Consumed by AJAX Unless Tab is Closed
http://code.google.com/p/chromium/issues/detail?id=52411
I'll have a look.
Comment #7 on issue 52411 by ant...@chromium.org: AJAX Memory Leak - Chrome
Never Releases Memory Consumed by AJAX Unless Tab is Closed
http://code.google.com/p/chromium/issues/detail?id=52411
Sorry, guys, I need more info.
First of all, please, if you have any extensions installed, it'd be great
if you could share the list with me.
http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/DynamicPopulate/DynamicPopulate.aspx
looks
fine to me: Tony.V...@PowerDNN.com, may you double check if you
experience any problem with the recent Chrome? a.rzadkowolski currently
sees none.
phis...@chromium.org: what kind of leak are you observing? Memory usage
can grow really high as only tiny JS objects are created, but we should
forcefully trigger GC when total memory usage will grow too high. Another
way to check if there is a real leak is to make a couple of heap snapshots
with Developer tools: heap snapshots both perform GC and could point out
what exactly is leaking.
Or just leave the tab in background and check it memory usage later.
If you still see a leak which breaks 512M limit on Windows, may I ask you
to give me a self-contained HTML?
And FYI, once there was a suspicion we have XHR leak pretty much like you
describe, but it turned to be false alarm.
dunn.matt.w: very important thing is to learn if you have any extensions
installed: some of them trigger leak like behaviour, esp. for site which
create many frames. Bug again, in my extension less Chrome I see no leaks.
Thanks a lot for reporting problematic case and sorry that I am bothering
you with additional stuff.
@antonm - the memory just grows. If I explicitly delete that object (notice
the "delete xhr;"), why does the memory keep on growing?
Hi all,
I just tested this again in Chrome 9.0 on the dev channel, and this is
still an issue. I do not have any extensions installed. I don't know how
to forcefully cause GC to happen, but I can tell you that it should have
happened automatically well before using 800MB of RAM.
-Tony V.
yep, I saw delete, but delete is only a hind and does nothing in v8, v8
releases memory only when performs GC.
There are several events which could trigger GC. In the most cases v8
triggers GC when a lot of memory for JS objects has been allocated.
There is a well-known problem with tiny v8 objects holding huge native
objects: think XHR requests where v8 create pretty small objects, roughly 4
words and keeps a pointer to WebKit string which might be pretty big or JS
wrappers for DOM objects.
To solve it v8 and WebKit has additional protocol like reporting amount of
external memory held by v8 strings or forcing GC when memory usage is
getting too high.
Resume: JS delete doesn't guarantee memory release and events which trigger
GC and hence memory release might be quite surprising.
Tony,
what exactly you're doing? 800M is definitely too much. But on my Chrome
(MacOS, 7.0.517.44) opening a site for a minute doesn't reveal any notable
memory usage growth.
Do you just keep site longer? Which sections do you navigate? What are
you doing?
Thanks a lot for keep an eye on this issue.
Hey again @antonm,
I am developing extension
https://chrome.google.com/extensions/detail/effhaohnpfmphdbipcijflpkkgpakcma
and it makes requests to www.facebook.com/reqs.php
in versions of chrome prior 9.0 the memory was just growing.
The file it's downloading is 500KB so it's a bit of data.
Please try requesting this address with phistuck code, it should give you
some clarification.
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();
}
In my case, there is an AJAX-based application that we use. Instead of
loading a new page, _EVERY_ request after the first one is retrieved via
ajax.
After using the app for a while, chrome consumes all that RAM.
@a.rzadkowolski: thanks, I experimented with things like that and observed
no memory leak (but at least for http://www.facebook.com/reqs.php I've got
zero length responseText
@Tony: Tony, to see what goes wrong I need a repro case.
@antonm if you get zero length you can't repro it :) You can try then:
http://www.facebook.com/?sk=games (it's almost the same size) with version
6 and 7 it grew up really fast to even 800MB (when using 10-15 seconds
timeout)
@a.rzadkowolski: please, find the attached file. It still reports
xhr.reponseText.length is 0. May you turn it into the repro? Thank you in
advance.
Attachments:
test.html 351 bytes
@antonm - try that inside the background page of the extension. Remember,
you cannot make cross origin requests with regular web pages, so you always
get no response through the API.
@antonm - Of course, add a permission for http://www.facebook.com.
@phistuck: do you suspect it's extensions related? if not, I'd rather have
a simple single page repro for it.
@antonm - No, I was just pointing out a way to get this actually working.
A simple page would not work on the file:// scheme, because of the security
policy Chrome maintains (no access to files from files or from anything
else).
You can run the script through the Developer Tools console when you are
within a Facebook page (so it would not be a cross origin request).
Or start Chrome with --disable-web-security.
I have included simple extension that experience this problem. (you must be
logged to facebook before using it)
Also an image: attached script was run for 15 minutes on both: Chrome 6
(lower row: 140MB) and Chrome 9 (upper row: 14MB). As you can see it was
fixed in chrome 9.
Attachments:
leak.zip 24.8 KB
mem_usage.png 4.7 KB
One more photo after more 39 minutes.
Attachments:
mem_usage2.png 53.2 KB
Anton, can you please re-visit?
Someone complains about very-similar leaks in Chrome 10 (April 2011)
http://habrahabr.ru/blogs/javascript/117909/
I did. And still I am not convinced it's a leak.
What I did: just add 5 forced gc (exposing it with --expose-gc flag) in
callbacks. Then ran it for ~10hrs. Results are no memory growth. There
is some fragmentation piling up, but that's due to the fact that GC picks
mark-sweep which doesn't do compaction.
Overall, notion of leak in GCed language is rather involved. And both V8
and V8 DOM bindings have a lot of various instruments to keep memory usage
under control while maintaining necessary performance.
The classic leak would be something which quickly exhausts the heap and
make Chrome crash with out of memory. Just memory growth, esp. flat or
until it reaches big numbers, might signify that v8 decided not to spend
too much time collecting all the garbage.
Leaving wonfit for now. But if I miss any points, please, let me know.
It appears that this is still an issue, at least on Windows 7.
Here's a fully standalone runnable test case that rapidly consumes all
available system memory and then crashes Chrome (18.0.1025.151 m) running
on Windows 7.
All this does is issues a new XMLHttpRequest for a JSON style response (a
static text file in this case, Response.txt) with a changing parameter on
the URL.
To run the test, just drop both the html file and the txt file into the
same dir of your server (I'm testing against Tomcat) and hit the HTML file
with Chrome.
Watching the windows Resource Monitor, one of the Chrome.exe processes will
rapidly consume all available memory until the browser crashes.
Regards
Paul Notley
Attachments:
XMLHttpRequest_leak.html 2.3 KB
Response.txt 174 KB
Comment #31 on issue 52411 by da...@chromium.org: AJAX Memory Leak - Chrome
Never Releases Memory Consumed by AJAX Unless Tab is Closed
http://code.google.com/p/chromium/issues/detail?id=52411
(No comment was entered for this change.)
Ulan, can you please take a look if the new script indeed does cause a
crash in V8? It might be a new, different problem. Anton said he can give
you assistance and background about this bug.