<legend id='b7os9'><style id='b7os9'><dir id='b7os9'><q id='b7os9'></q></dir></style></legend>
    <tfoot id='b7os9'></tfoot>

    <small id='b7os9'></small><noframes id='b7os9'>

    • <bdo id='b7os9'></bdo><ul id='b7os9'></ul>

      <i id='b7os9'><tr id='b7os9'><dt id='b7os9'><q id='b7os9'><span id='b7os9'><b id='b7os9'><form id='b7os9'><ins id='b7os9'></ins><ul id='b7os9'></ul><sub id='b7os9'></sub></form><legend id='b7os9'></legend><bdo id='b7os9'><pre id='b7os9'><center id='b7os9'></center></pre></bdo></b><th id='b7os9'></th></span></q></dt></tr></i><div id='b7os9'><tfoot id='b7os9'></tfoot><dl id='b7os9'><fieldset id='b7os9'></fieldset></dl></div>

    1. 是否有必要在递归调用的计时器内清除Timeout?

      时间:2024-04-19
      <i id='Y2noi'><tr id='Y2noi'><dt id='Y2noi'><q id='Y2noi'><span id='Y2noi'><b id='Y2noi'><form id='Y2noi'><ins id='Y2noi'></ins><ul id='Y2noi'></ul><sub id='Y2noi'></sub></form><legend id='Y2noi'></legend><bdo id='Y2noi'><pre id='Y2noi'><center id='Y2noi'></center></pre></bdo></b><th id='Y2noi'></th></span></q></dt></tr></i><div id='Y2noi'><tfoot id='Y2noi'></tfoot><dl id='Y2noi'><fieldset id='Y2noi'></fieldset></dl></div>
    2. <small id='Y2noi'></small><noframes id='Y2noi'>

          <bdo id='Y2noi'></bdo><ul id='Y2noi'></ul>

            • <tfoot id='Y2noi'></tfoot>

                <tbody id='Y2noi'></tbody>
              <legend id='Y2noi'><style id='Y2noi'><dir id='Y2noi'><q id='Y2noi'></q></dir></style></legend>

                本文介绍了是否有必要在递归调用的计时器内清除Timeout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                是否有必要在 Coffeescript 的递归调用函数中调用 clearTimeout() ?

                Is it necessary to call clearTimeout() inside a recursively invoked function in Coffeescript?

                我担心的是,如果这个函数每秒运行很多次,不调用 clearTimeout() 是否会随着时间的推移导致某种内存泄漏.我的想法是 JS 垃圾收集器处理这个,但想仔细检查.

                My concern is whether not calling clearTimeout() will possibly cause some sort of memory leak over time if this function is run many many times per second. My thinking is the JS garbage collector handles this, but want to double check.

                我正在研究的 websockets/socket.io 实现中的人为示例:

                A contrived example from a websockets/socket.io implementation I'm working on:

                socket.on 'dataReceived', => @_recursive_fn()
                
                _recursive_fn: ->
                  @timer = setTimeout (=>
                    clearTimeout(@timer) # is this necessary?
                    @_recursive_fn() if some_condition == true
                  ), 30
                

                推荐答案

                不,setTimeout 安排一次性事件.事件发生后,带有该句柄的 clearTimeout 将成为空操作.

                No, setTimeout schedules a one-off event. Once the event has occurred, clearTimeout with that handle is a no-op.

                这篇关于是否有必要在递归调用的计时器内清除Timeout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Flot Charts - 在单个 html 页面中处理多个 flot 下一篇:Backbone.js:模型没有出现

                相关文章

                <small id='24PiK'></small><noframes id='24PiK'>

              1. <i id='24PiK'><tr id='24PiK'><dt id='24PiK'><q id='24PiK'><span id='24PiK'><b id='24PiK'><form id='24PiK'><ins id='24PiK'></ins><ul id='24PiK'></ul><sub id='24PiK'></sub></form><legend id='24PiK'></legend><bdo id='24PiK'><pre id='24PiK'><center id='24PiK'></center></pre></bdo></b><th id='24PiK'></th></span></q></dt></tr></i><div id='24PiK'><tfoot id='24PiK'></tfoot><dl id='24PiK'><fieldset id='24PiK'></fieldset></dl></div>

                  <legend id='24PiK'><style id='24PiK'><dir id='24PiK'><q id='24PiK'></q></dir></style></legend>

                  1. <tfoot id='24PiK'></tfoot>
                    • <bdo id='24PiK'></bdo><ul id='24PiK'></ul>