TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Preventing memory leaks in Backbone.js

79 点作者 doctororange超过 12 年前

10 条评论

davidw超过 12 年前
Ugh. Examples use Coffeescript instead of universally accessible Javascript. Looks very useful though; I've just started learning about Backbone, and the lack of a "right way of doing things" is disconcerting, coming from a lot of Rails usage lately. It takes me back to the days of doing a lot of stuff by hand.<p>Even without that uncertainty, it's definitely a bit tricky to move to thinking about everything being in the browser.
评论 #4772771 未加载
评论 #4772615 未加载
评论 #4772787 未加载
评论 #4772803 未加载
ldehaan超过 12 年前
I agree on the whole coffeescript thing, really it detracts from what you are trying to show. But on to the real point of commenting; I am implementing a system using backbone because it is a requirement of the company I am contracting for. I am writing several..plugins..I suppose you would call them, to make backbone work more like angular.js. If you're having issues with backbone and have a choice, I strongly recommend checking out angular. it is quite amazing and very flexible. while it seems like it should be opinionated it is actually quite flexible on what you must do once you learn how it works. A great example is view compositioning, it has a very strong templating system using definitions to create your own element sections. I am having a really hard time liking backbone, if I have to write all this code, really I would much rather write my own library to handle this stuff. So just my point of view along with a suggestion on something that I believe can take you much further and reduce the time you spend on the b.s.
Jacob4u2超过 12 年前
I've been using chaplinjs as a backbone architecture for my last couple side projects and I really like it.<p><a href="https://github.com/chaplinjs/chaplin" rel="nofollow">https://github.com/chaplinjs/chaplin</a><p>Simplified router, subviews, model binding techniques like described in the OP are all helpfully baked in.
mikeknoop超过 12 年前
Two things you can do together to help, but need Backbone edge version (master) for the second, at the moment:<p><pre><code> 1. myModel.on('change:title', this.render, this); // inside `myView` 2. myView.dispose(); // when you are done with `myView` </code></pre> This will automatically remove all the referenced binds onto `myView` and simply removing the root view as OP mentions is sufficient.
评论 #4772282 未加载
bjhoops1超过 12 年前
Great pointing out that Backbone is <i>deceptively</i> simple. No best practices to be found on backbonejs.org.<p>Always worth considering using a framework layer like Marionette to help you with architecture. Otherwise you <i>will</i> end up writing something similar to it yourself. Which sometimes is necessary, but not always.
EzGraphs超过 12 年前
Javascript memory leaks can be identified using Browser Profiler (e.g. <a href="https://developers.google.com/chrome-developer-tools/docs/heap-profiling" rel="nofollow">https://developers.google.com/chrome-developer-tools/docs/he...</a>). Are there any other better/recommended tools for the job?
评论 #4772811 未加载
SeppoErviala超过 12 年前
Don't nested child views get garbage collected when the root view is removed?
评论 #4772061 未加载
politician超过 12 年前
I highly recommend onsi's Backbone.coccyx [1] for ensuring that views are torn down correctly.<p><a href="https://github.com/onsi/coccyx" rel="nofollow">https://github.com/onsi/coccyx</a>
sontek超过 12 年前
Backbone.Marionette is pretty good at solving a lot of these issues but this is a great blog on how to do it yourself.
odiroot超过 12 年前
AFAIR, it's one of the issues Backbone.Marionette is trying to fix with its bindTo/close solution.