开发者

Apparent memory leak in web application (maybe from AJAX?)

开发者 https://www.devze.com 2022-12-12 08:52 出处:网络
I\'m running an AJAX request from a JavaScript-powered (+jQuery) webpage every 5 seconds for a set of JSON data. I left my application on overnight, and by morning my computer had completely frozen. I

I'm running an AJAX request from a JavaScript-powered (+jQuery) webpage every 5 seconds for a set of JSON data. I left my application on overnight, and by morning my computer had completely frozen. I narrowed it down to my web browser and now, using Google Chrome's Resource Tracker, I can see that each request contributes a new memory expenditure, and the old JSON lingers.

As the source JSON is constantly changing, I call it with the timestamp as a parameter, to avoid caching... I realise caching would solve this problem, but it would also make my data invalid.

Any ideas? I'm overwriting the previous variable, so I don't see why the previous data should be retained. The memory increases don't happen at the same interval at the AJAX requests, so maybe its something else. I'd be happy to send someone the 开发者_运维知识库code privately, if it would help.

Thanks all :-)

Gausie


What are you doing with the data ?

It is probably not jquery's ajax the culprit.

Is you dom growing ? Do you have forgotten to declare a variable using the var prefix ? do you delete content using innerHTML = '' ?


First, make sure that it is ajax request that causes the leak. Don't request this ajax every 5 seconds and check if memory still leaks.

If it is the request, maybe you overrite one variable, but you have another variable pointing at this data? Something like this:

var a = json_object;
var b = json_object;
//A lot of other code here
var a = json_object2;

json_object is still in the memory, var b points at it. If there is no var b, maybe you add it to some map or array? In such case map or array points at it.


It can't be answered cause you didn't provide some code sample. In general check for improper use of closure... Anyway - check this post http://www.crockford.com/javascript/memory/leak.html and use Google or provide some examples. Good luck!

0

精彩评论

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