Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't seem to cleanup detached DOM elements
    primarykey
    data
    text
    <p>I'm using <a href="http://jqueryui.com/tabs/" rel="noreferrer">jquery-ui Tabs</a> 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 at the heap in Chrome DevTools Profiles (after a tab has been removed) you'll see that the tab li and div elements are still present, but detached. Over time, the repeated addition/removal of tabs causes these elements to accumulate. For example, if you add a tab 10 times, there will be 10 detached div elements and 10 detached li elements showing up in the heap snapshot:</p> <p><img src="https://i.stack.imgur.com/5dHou.png" alt="Heap snapshot with detached elements"></p> <p>I have the following views:</p> <pre><code>TabLabel = Marionette.ItemView.extend({ template: "#tab-label", tagName: "li", events: { "click .ui-icon-close": "closeTab" }, closeTab: function(e) { this.$el.contents().remove(); this.model.collection.remove(this.model); $("#main-container").tabs("refresh"); this.close(); } }); TabContainer = Marionette.ItemView.extend({ template: "#tab-container", tagName: "div", onBeforeRender: function() { this.$el.attr("id", "div-" + this.id); }, onClose: function() { // This removes the region that contains the container App.layout.removeRegion(this.containerRegion); } }); TabLabels = Marionette.CollectionView.extend({ tagName: "ul" }); TabContainers = Marionette.CollectionView.extend({ tagName: "div" }); </code></pre> <p>The views are instantiated like so:</p> <pre><code>tabs = new TabsCollection(); // Create a new collection instance var tabLabelView = new TabLabels({ itemView: TabLabel, collection: tabs }); var tabContainerView = new TabContainers({ itemView: TabContainer, collection: tabs }); </code></pre> <p>As you can see, the views both refer to the same collection; each model in the collection can be said to represent a single tab (it just so happens that the model contains the necessary information to satisfy jquery-ui tabs). The views are shown in a region via Marionette.Layout... pretty standard. Adding a tab is accomplished by clicking a link in the tab container; all this does is adds another model to the collection and then calls tabs("refresh") on the main container, which makes the new tab appear. Removing a tab is accomplished by clicking an "X" icon in the upper right-hand corner of the tab. </p> <p>I've spent a lot of time trying to track down this leak and I can't figure out if it's a problem in my code (the way I'm closing views/models/etc. perhaps?) or if it's a problem in the jquery-ui tabs plugin. </p> <p>Thoughts? Thanks in advance!</p> <p><strong>Update #1</strong> As requested, here is a <a href="http://jsfiddle.net/dBmAe/30/" rel="noreferrer">jsfiddle</a> demonstrating the problem -- just close the tabs and you'll see that detached elements are left behind. </p> <p>Also, a screenshot:</p> <p><img src="https://i.stack.imgur.com/rZtL8.png" alt="enter image description here"></p> <p><strong>Update #2</strong> This appears to be a leak in the jquery-ui tabs widget. The same behavior occurs in the <a href="http://jqueryui.com/tabs/#manipulation" rel="noreferrer">widget demonstration</a> on the jquery-ui website. I added a few tabs and then closed them out and sure enough, they persisted:</p> <p><img src="https://i.stack.imgur.com/aZEZM.png" alt="enter image description here"></p> <p>I've tested this with the latest (at the time of this writing) version of jQuery UI (1.10.3) and the previous version (1.10.2).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload