View Full Version : JS Memory Leak

05-02-2006, 10:56 AM
I've been putting together a small pet project. Once it was finished i realised it had a gigantic memory leak inside of it. I tried to read up on the subject, but couldn't find the source of the problem via the articals.

This site is very simple, so I'd think idenifying (and hopefully fixing) the problem would be easy. Here is the relavent portions of JS (followed by links to the full page incase you need to see that):

<input value="Run" onclick="parent.script.location='script.php'" type="button">

. . .

<form name="runCount"><input size="10" name="totalClicks" align="center" type="text" value="0"></form>

var grabVal=parseFloat(parent.main.document.runCount.totalClicks.value);
grabVal = grabVal + .25;
$lines = file('urls.txt');
$line_number = mt_rand(0,sizeof($lines)-1);
$location=str_replace("\n", "", $killreturn);
$location=str_replace("\r", "", $location);
print "parent.change.location=\"$location\";";
The php just selects a random webpage for the "change" frame to be redirected to.

I also have adbrite code installed which uses JS, but the page still leaks like crazy even with it removed.

Incase you need more sorounding information here are the URLs you can directly access the project with:
http://gaiabot.awardspace.com/index.html (frame set)
http://gaiabot.awardspace.com/main.html (main body)
http://gaiabot.awardspace.com/script2.txt (source code of script.php so you can actually read it).

Any help would be very very much appreciated!


05-02-2006, 11:55 AM
my FF says thare is no web page on those addresses...

Anyway, if you show us the php code but looking for a javascript solution could not be a wise decision, as not all the people here know php. Better show us what php writes as HTML/Javascript on the page (same as View Source)

05-02-2006, 12:34 PM
That's very strange. I rechecked all the links and they seem to work fine.

As far as what the phpcode writes once it's exicuted that looks like this:

<html><head><meta http-equiv="refresh" content="2.5"></head>
<body bgcolor="black" text="red">
<script language="javascript">
var grabVal=parseFloat(parent.main.document.runCount.totalClicks.value);
grabVal = grabVal + .25;

05-02-2006, 04:28 PM
How do you know you have a memory leak?

The only memory leak I'm aware of in the current browser environment is in IE6 and has to do with circular references involving DOM elements and JavaScript objects, which you don't seem to have.

05-02-2006, 05:48 PM
I believe i have a memory leak because the site progressivly uses more and more (and more) memory the longer it runs. We're not talking about small increases either. Like 80mb after about a minutes or two. Going up to a couple hundred until it's bogging down the system so much that it slows to a crawl.

Also, the memory stays reserved even after i exit the page. I need to restart the browser in order to reclaim it. I found this leak is active in both firefox and in IE (havn't tried it on any other browsers yet, but i'd imagine that it'd be similar).

05-02-2006, 06:12 PM
and the script segment you posted is the only javascript on the page?

05-02-2006, 07:01 PM
yeah, pretty much. There is also code from adbrite (which calls an external JS), but the page leaks like crazy even when i remove it.

I'm rather confused.