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

  • Home
  • SEARCH
  • 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 6966255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:10:06+00:00 2026-05-27T16:10:06+00:00

I have some code like this: var User = function () { _.bindAll(this) this.UserList

  • 0

I have some code like this:

var User = function () {
  _.bindAll(this)

  this.UserList = Backbone.Collection.extend({
    model: UserModel
    // ...
  });

  this.UserListView = Backbone.View.extend({
  // ... etc
}

User.prototype.display = function() {
  var self = this
  self.collection = new self.UserList
  self.collection.fetch({
    success: function(collection, response) {
      self.users = new self.UserListView({
        collection: self.collection
      });
    }
  })
};


var user = new User()

route("users", function () {
  user.display()
})

My question is, is this going to cause memory issues? Every time the user arrives on the user/:userPage route the view, collection, etc are all going to be recreated. Will the old ones be deleted or do I have to delete it manually?

Should I be doing this:

User.prototype.display = function() {
  var self = this
  delete self.collection
  self.collection = new self.UserList
  self.collection.fetch({
    success: function(collection, response) {
      delete self.users
      self.users = new self.UserListView({
        collection: self.collection
      });
    }
  })
};

Also other general advice on my example code is appreciated too.

  • 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-05-27T16:10:07+00:00Added an answer on May 27, 2026 at 4:10 pm

    This is utterly useless:

       delete self.collection
       self.collection = new self.UserList
    

    All delete does is remove collection field from the self object, and then you immediately recreate it. Just do the assignment.

    I think that you think that delete self.collection should somehow cause the garbage-collection of the object pointed to by the field. It doesn’t.

    Also, don’t use self as a variable name. The browser uses it to mean, uh, something.

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

Sidebar

Related Questions

This is a really basic question but... I have some code like this var
I have some LINQ code that generates a list of strings, like this: var
I have a javascript file which has some code somewhat like this: var Slide
I have some code like this in a winforms app I was writing to
I have some code like this: If key.Equals(search, StringComparison.OrdinalIgnoreCase) Then DoSomething() End If I
I have some code like this: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Save([Bind(Prefix=)]Person person) { String s
I have some code like this: doDatabaseFetch { ... @synchronized(self) { ... } }
Let's say I have some code like this: <html> <head><title>Title</title></head> <body> <?php if (!$someCondition){
Let's say I have some code like this if(isset($_GET['foo'])) //do something if(isset($_GET['bar'])) //do something
Here's my problem - I have some code like this: <mx:Canvas width=300 height=300> <mx:Button

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.