jQuery bind() unbind() and on() and off()

后端 未结 3 877
夕颜
夕颜 2021-02-10 05:05

Im working on a small adminarea for a webpage.

Does it make sense to unbind events for increasing performance(client)? Or does it cost more performance to unbind events

3条回答
  •  你的背包
    2021-02-10 05:43

    If you try to bind and unbind you are creating race conditions for the garbage collector to actually come in and clean up your code. It is best to bind once and not have to bind again. If your client side is expected to run for long periods of time (weeks, months) then you should look into memory management and memory leaks as more of a concern for performance.

    Binding-unbinding (if not done correctly) may produce memory leaks which are hard to find. If you are using webkit, take heap snapshots of your performance with unbinding versus binding once and then you can make the best decision.

    Here's a link:

    http://addyosmani.com/blog/taming-the-unicorn-easing-javascript-memory-profiling-in-devtools/

提交回复
热议问题