I notice that my app starts to become sluggish when I change urls too many times. I suspect this is because I have the routes set up in a way that they are instantiating a new view every time the url is visited, not sure if there is another way to do this. It may be that I don't understand javascript enough.What is happening to the views that I instantiated after they are not being used anymore, or in other words when I visit a new route?
var Router = Backbone.Router.extend({
routes: {
'':'doSomething',
'helloworld':'doSomethingElse'
}
});
var app_router = new Router;
app_router.on('route:doSomething', function() {
var thing = new SomeModel();
new someView({model : thing});
});
app_router.on('route:doSomethingElse', function() {
var thing = new SomeModel();
new someOtherView({model : thing});
});
so in this simple example, if I were to click back and fourth on links <a href="#">
and <a href="#helloworld">
would there just be a build up of view and model objects? and if so would it be a problem.I would imagine that memory would be eaten up but I may just not be understanding things correctly.
Here is a screenshot of the timeline as I click back and fourth between two routes. It seems that there is a build up of listeners which I am guessing is coming from the event listeners that I have set on one of the particular views. I think it is creating new listeners on every instantiation.