Home >Web Front-end >JS Tutorial >js memory release problem_javascript skills

js memory release problem_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:28:481095browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn