views:

90

answers:

1

I have the code below on a social network site, it loads a file that shows users new notification messages if they exist.

Problem is when I leave the page open for a while, it eventually consumes too much memory on my PC and starts to make firefox non-responsive and throws an error message saying that memory is getting low and asking if I should abort the script or something along those line.

Is there a way to do what I have it doing but without using up so much memory over time?

<script type='text/javascript'> 
$(document).ready(function(){ 
     var updatenotification = function(){ 
          $('#notificationcontainer') 
               .load('http://localhost/member/beta_new/notifications.inc.php') 
               .fadeIn("slow"); 
     }; 
     var auto_refresh = setInterval(function(){updatenotification();}, 60000); 
     updatenotification(); 
}); 
</script>
+1  A: 

What exactly do you return. I'll assume it is a large ish dom fragment. You could change the code to just return a small json string, check if there is a valid new notification and then write some markup into the div rather than reloading it each time regardless if there are new notifications. Can you maybe show the markup that you are returning.

I am making a few too many assumptions without knowing exactly what your returning. If it is just a tiny html fragement I cant really see the issue. The script looks ok and should not be causing the issues you speak about.

Also remember that firebug does have big issues at the moment. There are some pretty nasty leaky bugs that cause the memory warning dialog when browsing heavyish ajax/js sites like StackOverflow, Netvibes. Your average user (I assume!) will not have firebug so will not see anything

redsquare
that could be the issue as I am using firebug.The data from the included file depends on what kind of notifications are present, it dynamicly generated but for the sake of this issue, it happens even when the file is completety empty so there is nothing outputed to the screen when no notifications for a user exist
jasondavis
Disable FB and see how you go. Else use chrome and/or even ie8 with its developer tools when you need to debug.
redsquare
Yeah I generaly use chrome but I just like to fix things best I can so everybody has a good experience on my site, thanks for the tips
jasondavis
I really like the idea you mention of getting just a json string, I have no clue where to even start with that but it sounds like it would be better with bandwidth as well
jasondavis