Tonight I ran into a bug, in the Refresh page when the browser occupied by the memory is constantly rising, chrome process CPU occupancy rate is also maintained around 50, do not know what is the reason
Looking for a long time, commented that most of the code part of the slowly ruled out, finally found that the error is JavaScript, it is not clear to look at what is the reason, wrote a basic JS code to continue to loop, finally found that the call to use the function of the problem
SetTimeout ("ShowTime ()", 1000);
SetInterval ("ShowTime ()", 1000);
These two functions are called every 1 seconds, but the following one will accumulate memory consumption, and the above is the memory resource is unchanged.
SetTimeout () This function only executes one code at a time, and setinterval () does not stop until the clearinterval () or window is closed until the function is called. This results in a large amount of memory resources being consumed.
Because I do not understand JS, so the understanding is not very deep
<script language= "JavaScript" >function ShowTime () {var date=new date (); var hours=date.gethours (); var minutes= Date.getminutes (); var seconds=date.getseconds (); if (hours.tostring (). length = = 1) { hours= ' 0 ' +hours;} if (minutes.tostring (). length = = 1) { minutes= ' 0 ' +minutes;} if (seconds.tostring (). length = = 1) { seconds= ' 0 ' +seconds;} var formattime=hours+ ":" +minutes+ ":" +seconds;settimeout ("ShowTime ()", "N"),/*setinterval ("ShowTime ()", 1000); */ document.getElementById ("Time"). Innerhtml=formattime;} </script>
A bug I ran into last night.