Gausie
Gausie

Reputation: 4359

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

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

Upvotes: 1

Views: 327

Answers (3)

Olivvv
Olivvv

Reputation: 1200

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 = '' ?

Upvotes: 1

NilColor
NilColor

Reputation: 3532

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!

Upvotes: 0

amorfis
amorfis

Reputation: 15770

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.

Upvotes: 0

Related Questions