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
https://forums.phpfreaks.com/topic/176681-memmory-problem/
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
https://forums.phpfreaks.com/topic/176681-memmory-problem/#findComment-931896
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
https://forums.phpfreaks.com/topic/176681-memmory-problem/#findComment-933760
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
https://forums.phpfreaks.com/topic/176681-memmory-problem/#findComment-933833
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.