Reprinted: http://flex4jiaocheng.com/blog/325
You should be familiar with the setTimeout method, and the setinterval method is usually used less frequently. In fact, both of them are very useful "timers", the difference is as follows:
SetTimeout (function, Int, null): uint
It suspends the int ms before executing the function, and the function is executed only once.
Setinterval (function, Int, null): uint
It will pause the function execution after int milliseconds, pause the function execution after int milliseconds again, and then pause the function execution after int milliseconds again ...... (I think you understand what I mean, haha ~~)
So the question is, how can we stop the setinterval method? What's the purpose of returning a uint? The "key" of this article is here.
In fact, we usually only use the setTimeout and setinterval methods, but seldom remember to call the cleartimeout and clearinterval methods to remove the listener added to the program by the set method. This is also a cause of memory vulnerabilities, their usage is as follows:
Cleartimeout (uint): void
It finds the corresponding time listener through the uint (ID of setTimeout) returned by setTimeout, and removes her.
Clearinterval (uint): void
It finds the corresponding time listener through the uint (setinterval ID) returned by setinterval and removes her. This will stop the infinite loop of setinterval.
You must remember to call the cleartimeout and clearinterval methods after using the setTimeout and setinterval methods !!