javascript memory leaks

后端 未结 5 612
天涯浪人
天涯浪人 2020-12-10 02:25

i am using jquery and doing something like this

DOM:

5条回答
  •  一生所求
    2020-12-10 02:40

    Since you're constantly referring to $('#parent'), you should create a reference to that object in the global scope so that jQuery isn't constantly looking for the object on each request. Doing this, you're essentially caching the reference to the object, which will cut down on memory usage tremendously.

    _parent = $('#parent');
    

    ...

    function(){ _parent.append('1'); }
    

    Edit: I picked up this tip from this article on jQuery Performance Rules

提交回复
热议问题