Home >Web Front-end >JS Tutorial >js memory release problem_javascript skills
CollectGarbage();
setTimeout("CollectGarbage();", 1);
The reason why setTimeout() is used here is because it can completely recycle all current objects and prevent references between variables from causing release failure. , can be used as a safeguard measure. Logically speaking, it will not be implemented here.
When using it, please note that it must be executed after all functions have been executed, otherwise, setTimeout(), setIntervalue(), etc. will not work properly.
In addition, avoid using it indiscriminately. Generally speaking, emptying the top-level object "var xxx='ss';xxx=null;" can help the browser release memory. IE releases it when it is minimized and closed. Therefore, leaving the IE window open for a long time will cause IE to slow down when it is opened again.