Is it necessary to call clearTimeout()
inside a recursively invoked function in Coffeescript?
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.
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