Can't seem to cleanup detached DOM elements

前端 未结 2 824
孤街浪徒
孤街浪徒 2021-01-31 20:28

I\'m using jquery-ui Tabs and I\'m having a problem that occurs when a tab has been removed. The tab appears to be removed, along with its content div but when you take a look a

2条回答
  •  难免孤独
    2021-01-31 20:57

    Is there a reason why you use this.$el.contents().remove() instead of this.$el.empty()?

    Using this.$el.empty() in that jsFiddle of yours seemed to remedy the detached NodeList.

    A few notes memory profiling:

    • watch http://www.youtube.com/watch?v=L3ugr9BJqIs
    • Use the 3 snapshots method, 2 is not enough. What does that mean?
      • Start fresh, incognito mode and refreshed
      • Take snapshot (forced GC will happen every time you take snapshot)
      • Do something, take snapshot (gc)
      • Do something similar, take snapshot (gc)
      • Compare snapshot 2 with snapshot 1, find deltas with +
      • Choose Summary and Objects allocated between Snapshots 1 and 2 for snapshot 3
      • Look for stuff that you found comparing 2 and 1 that shouldn´t be there. These are the leeks

    I have found cases where jQuery seems to leek because they save the current jQuery object in .prevObject when doing some operations like calling .add(). Maybe that call to .contents() do some funky magic.

提交回复
热议问题