Giter VIP home page Giter VIP logo

Comments (2)

ecbypi avatar ecbypi commented on June 21, 2024

To confirm I understand the problem, I tried to call this from leave() on the view, but that did not work. means code similar to the following?

var NodeView = CompositeView.extend({
  render: function() {
    this.$el.plugin();
  },

  leave: function() {
    this.$el.plugin("destroy");
    CompositeView.prototype.leave.call(this);
  }
});

var parent = new NodeView();
var child = new NodeView();
parent.appendChild(child);

  // `.plugin("destroy")` in custom `leave()` does not work when called by `child`
parent.leave();

If so, we can change the order. From git history the current order is how the methods were added.

from backbone-support.

Kufert avatar Kufert commented on June 21, 2024

@ecbypi yes that's the case. The issue is that jQuery plugins, such as typeahead, bootstrap-timepicker and many others, are not destroyed properly.

Reason is that when adding anything to the DOM using jQuery, jQuery saves a reference to that item event listeners. That data is stored under $.cache (what's $.cache?).
The problem is that even when I try to use destroy on the leave method, the event listeners are not removed as their bound element is not in the DOM anymore, which it turn create a memory leak.

When calling _leaveChildren() before remove(), the leak is prevented.

  leave: function() {
    this.trigger('leave');
    this.unbind();
    this.stopListening();
    this._leaveChildren();
    this.remove();
    this._removeFromParent();
  },

make it all makes sense :)

from backbone-support.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.