Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: JS Memory Leak

  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JS Memory Leak

    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):

    Code:
    <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>
    Code:
    var grabVal=parseFloat(parent.main.document.runCount.totalClicks.value);
    grabVal = grabVal + .25;
    parent.main.document.runCount.totalClicks.value=grabVal;
    <?php
        $lines = file('urls.txt');
          $line_number = mt_rand(0,sizeof($lines)-1);
          $killreturn=$lines[$line_number];
        $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!

    Thanks,
    --Paolo

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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)
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    May 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    Code:
    <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;
    parent.main.document.runCount.totalClicks.value=grabVal;
    parent.change.location="http://www.gaiaonline.com/forum/viewtopic.php?t=12946045&page=9";
    //-->
    </script>
    </body></html>

  • #4
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    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.

  • #5
    New Coder
    Join Date
    May 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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).

  • #6
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    and the script segment you posted is the only javascript on the page?

  • #7
    New Coder
    Join Date
    May 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •