Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you test whether Backbone.js views are getting properly unbound() and destroyed()?

I'm currently diving into Backbone.js, and working on a few complex web apps. I've done a fair amount of research on view (and nested view) management, and making sure that all events are unbound when a view is left or destroyed. I'm currently using ThoughtBot's solution to this - Backbone Support (using composite views and swapping routers).

Even though I'm not encountering any tell-tale problems regarding the above, is there any way to make sure or test that views are getting properly cleaned up? I would love be to be able to make sure that I'm going about things properly!

Thanks!

like image 935
Whoa Avatar asked Nov 04 '22 02:11

Whoa


1 Answers

You could use the memory profiler in Chrome's dev tools. Set up a test that creates 1000 Views, destroys them, and then repeats over and over.

The profiler should show gradual increases in memory punctuated by steep declines when garbage collection runs. If things are getting cleaned up properly, your overall average memory usage over a sufficiently long duration should be consistent.

like image 74
Kevin Ennis Avatar answered Nov 09 '22 08:11

Kevin Ennis