Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8228073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:20:41+00:00 2026-06-07T16:20:41+00:00

We have some legacy non-backbone code in our web application. Although we attach views

  • 0

We have some legacy non-backbone code in our web application. Although we attach views to existing DOM elements there is still some yet-to-be-refactored code that deletes certain DOM elements i.e. the delete call doesn’t go through the view but is more like a jQuery call $('#domID').remove();

I have a nagging feeling that the backbone view probably hangs around as a zombie, but I don’t have a way to see it? Is this harmful? Should we make it priority to refactor and have all the deletes go via the view and call view.remove() and view.unbind() for proper deletion?

Would the view be garbage collected if the DOM node is deleted independently? I guess if not if it’s bound to some event, but what if it isn’t?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:20:44+00:00Added an answer on June 7, 2026 at 4:20 pm

    The view will only linger on if there is a reference to it somewhere. There are four sources of stray references to consider:

    1. Bindings to models and collections, i.e. this.collection.on('reset', this.render) and such.
    2. Bindings to DOM objects through the view’s events.
    3. Bindings to DOM objects through direct $(...).on(...) calls.
    4. Plain old variable references such as this.current_view = new V(...).

    (1) is normally handled by the view’s remove method and you have to call remove yourself, there’s nothing in Backbone or jQuery that can do this for you. For example: http://jsfiddle.net/ambiguous/e574Z/

    (2) is easy. Backbone views use a single delegate call to bind the view’s events to the view’s el. So, if you remove the view’s el through a simple $(x).remove() then the event reference goes away. However, if you’re attaching different views to the same el, you’ll need to call undelegateEvents to detach the delegate; this would normally be done in a remove method:

    remove: function() {
        this.undelegateEvents();
        return this;
    }
    

    but, again, you have to call remove yourself somewhere.

    (3) is rare but sometimes necessary in the case of window scroll events, body click events for dialogs, and things like that. Of course, you have to clean these up yourself as Backbone can’t know what you’re doing behind its back and the elements that you’re binding to would be outside of the view’s el (or you’d be in (2)). Where would you clean these up? The remove method of course.

    (4) is, as always, up to you. Usually, this sort of thing is handled like this:

    if(this.current_view)
        this.current_view.remove();
    this.current_view = null;
    

    Yes, there’s remove again.


    So, if all you have are things like (2), then $('#domID').remove(); will be fine and shouldn’t leave any zombies; in fact, the default remove implementation is just this.$el.remove() and the documentation says as much:

    remove view.remove()

    Convenience function for removing the view from the DOM. Equivalent to calling $(view.el).remove();

    However, you probably have some things like (1) involved as well so adding/updating all your remove methods and calling view.remove() to remove views would be a good idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I have some legacy ASP.NET 2.0 code that uses the ASP Xml web
We have some legacy ASP.NET code that detects if a request is secure, and
I have some legacy code that was used to monitor my applications cpu,memory etc
I have some legacy C++ code that I am trying to understand a bit
I have some data (produced by a legacy application) that I know is invalid
I need to integrate some legacy 32-bit code - for which I don't have
I have encountered a weird situation while updating/upgrading some legacy code. I have a
In support of some legacy code, I have to read a text file and
I have some legacy code that contains this typedef: typedef enum simple_op_enum { #define
I have some legacy code that uses Interlocked.Equals to compare values. The values may

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.