Skip to content

Memory leak with idle checking #50

@jacwright

Description

@jacwright

When idle checking is on, every mouse move, keystroke, and scroll event calls wake which iterates through an array of old timers and clears them (though only effectively clearing the last timer which would be the only one ever active). This array grows unbounded with each event. An array should not be used here.

Current:

trackIdleStatus = ->
    timer = []
    wakeUp = ->
      timer.map(clearTimeout);
      ifvisible.wakeup()  if status isnt "active"
      idleStartedTime = +(new Date())
      timer.push setTimeout(->
        ifvisible.idle()  if status is "active"
      , idleTime)
...

Fix:

trackIdleStatus = ->
    timer = null # No array, just a reference to the last timeout id
    wakeUp = ->
      clearTimeout(timer); # Clear previous timeout. A noop if the timeout already ran
      ifvisible.wakeup()  if status isnt "active"
      idleStartedTime = +(new Date())
      timer = setTimeout(->
        ifvisible.idle()  if status is "active"
      , idleTime)
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions