Internet Explorer 7/Backbone 中可能存在内存泄漏吗?
我一直在研究 Backbone,看看这个框架是否是从现在开始并在我们的应用程序中继续构建的一个不错的选择。一项要求是我们必须支持 Internet Explorer 7+,另一项要求是每页至少显示 200 个项目。
为了测试该框架,我构建了一个非常简单的列表,它在除 Internet Explorer 7 之外的所有主要浏览器中都能完美运行。似乎存在一些内存泄漏,因为每次我重置数据时,总渲染时间都会增加。
我已经设置了一些测试场景:
声明事件:http://jsfiddle.net /mefraimsson/a2YMF/
没有声明事件:http://jsfiddle.net/mefraimsson/u6byQ/
我的一个想法是,当元素被删除并添加到 DOM 时,声明的事件永远不会被清除。当我运行“没有声明事件”的测试场景时,频繁单击“重新加载数据”,渲染时间相当稳定,但运行“声明事件”时,渲染时间会迅速增加,并且 IE7 使用的内存量也会增加。这就是为什么我认为某处存在内存泄漏。
- 有人有使用 Backbone 渲染如此大量数据的经验吗?
- 有人在使用 Backbone 时遇到过内存泄漏问题吗?
- 当使用 Backbone 处理如此大量的数据时,您是否推荐另一种方法?与其使用大量子视图,而使用一个视图并迭代模板中的数据可能是一种可能的解决方案,但感觉您没有充分利用 Backbone?
- 您有何看法,您认为这与事件的声明有关,还是 Backbone 的实现导致了内存泄漏?
提前致谢
I've been playing around with Backbone to see if this framework is a good choice to build on from now on and forward in our application. One requirement is that we must support Internet Explorer 7+ and another is to show at least 200 items per page.
To test the framework I've built a pretty simple list and it works flawlessy in all major browsers except Internet Explorer 7. It seems like there are some memory leaks since each time I reset the data the total rendering time are increased.
I've setup some test scenarios:
With events declared: http://jsfiddle.net/mefraimsson/a2YMF/
Without events declared: http://jsfiddle.net/mefraimsson/u6byQ/
One idea I had was that the events declared never was cleaned up when elements was removed and added to the DOM. When I run the test scenario "without events declared" clicking Reload data frequently the rendering time are pretty stable, but running "With events declared" the rendering time are increased rapidly and the amount of memory used for IE7 is increased. That's why I think that there is some memory leak somewhere.
- Are there anyone who have experience with rendering of such large amount of data with Backbone?
- Are there anyone who have experienced memory leak problems working with Backbone?
- Do you recommend another approach when working with such large amount of data with Backbone? Instead of a large amount of sub-views use one view and iterate over data in template could be a possible solution, but then it feels like you don't get the most out of Backbone?
- What is your opinion, do you think it is related to the declaration of events or is it the implemenation of Backbone that's leaking memory?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,内存泄漏是 Javascript 应用程序中的一个常见问题。我认为有一些框架试图为您处理这个问题,但主干却没有。您使用的浏览器确实在如何注意到这些泄漏及其引起的问题方面存在一些差异,但它们也仍然存在于其他浏览器中。通常不是浏览器的问题,而是 Javascript 中通过使用回调函数处理事件绑定的方式有问题。
我写了一篇文章讨论这个问题,并提出了处理方法的建议,特别是视图:http://lostechies.com/derickbailey/2011/09 /15/zombies-run-managing-page-transitions-in-backbone-apps/
请务必阅读评论。那里还有一些处理内存泄漏的其他很好的建议。
Memory leaks are a common problem in Javascript apps in general. I think there are some frameworks which try to handle this for you, but backbone doesn't. The browser you're using does make some difference in how those leaks are noticed and the problems they cause, but they still exist in other browsers, too. It's generally not the browser that's at fault, but the way event binding is handled in Javascript through the use of callback functions.
I wrote an article discussing this with a suggestion for a way to handle it, specifically with views: http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-apps/
Be sure to read the comments, too. There are some other great suggestions for handling memory leaks in there.