Jump to content

memmory problem


jve2211

Recommended Posts

hi. i use this script and every second the browser i open it with uses more memory. is there any way to fix this.

 


function getTijdData()
{
var xmlhttp = GetXmlHttpObject();
var returnString;

xmlhttp.onreadystatechange=function()
{
	if(xmlhttp.readyState==4)
		 { 
			returnString = xmlhttp.responseText;
		 	tijdDiv.innerHTML = returnString;			
	     }
}

url = "checkTime.php";

xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(null);

setTimeout('getTijdData()', 1000);
}


//server script


<?

$tijd = date("H:i:s");

echo $tijd;


?>




 

 

 

Link to comment
Share on other sites

Actually, if my logic is correct, the setTimeout needs to be moved into the readyState... part.

 

 

Since it's asynchronous, the function is called, then 1 second later it's called again, then 1 second later it's called again.  Regardless of how many pending requests there are.  So, if your requests are taking more than 1 second, it will eventually start to have more and more requests each second.

Link to comment
Share on other sites

you are right. this all seems quite logical indeed. but it doesnt solve my problem.. my browser just keeps using more and more memory untill i get an out of memory at line... error. i need some way to empty the browsers cash so that it doesnt store the previous time values all the time in the clients system memory.. the website works fine just starts to give broblems afther some time because of this memory issue. so if anyone knows some way to do this. please tell me how :)

Link to comment
Share on other sites

Hi

 

Only other thing I can think to do would be to destroy the xmlhttp object once you have finished with it. This would only do any good if the function that is called onreadystatechange continues to exist after completion and is just builing up and taking more space.

 

Something like this:-

 

function getTijdData()
{
var xmlhttp = GetXmlHttpObject();
var returnString;

   xmlhttp.onreadystatechange=function()
   {
      if(xmlhttp.readyState==4)
        {
            returnString = xmlhttp.responseText;
            document.getElementById('tijdDiv').innerHTML = returnString;  
		setTimeout('getTijdData()', 1000);
		delete xmlhttp;
         }
}
url = "checkTime.php";
xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(null);
}

 

All the best

 

Keith

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.