简体   繁体   English

Internet Explorer 7 / Backbone中可能存在内存泄漏?

[英]Possible memory leaks in Internet Explorer 7/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. 我一直在玩Backbone,看看这个框架是不是一个很好的选择,从现在开始在我们的应用程序中继续前进。 One requirement is that we must support Internet Explorer 7+ and another is to show at least 200 items per page. 一个要求是我们必须支持Internet Explorer 7+,另一个要求是每页显示至少200个项目。

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. 为了测试框架我已经构建了一个非常简单的列表,它在除Internet Explorer 7之外的所有主流浏览器中都可以运行。看起来有一些内存泄漏,因为每次重置数据时总渲染时间都会增加。

I've setup some test scenarios: 我已经设置了一些测试场景:

With events declared: http://jsfiddle.net/mefraimsson/a2YMF/ 宣布事件: http//jsfiddle.net/mefraimsson/a2YMF/

Without events declared: http://jsfiddle.net/mefraimsson/u6byQ/ 没有宣布事件: 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. 我有一个想法是,当元素被删除并添加到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. 当我运行测试场景“没有声明事件”时,经常单击重新加载数据,渲染时间非常稳定,但运行“声明事件”时,渲染时间会迅速增加,并且用于IE7的内存量会增加。 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? 是否有人有使用Backbone渲染如此大量数据的经验?
  • Are there anyone who have experienced memory leak problems working with Backbone? 是否有人使用Backbone时遇到内存泄漏问题?
  • Do you recommend another approach when working with such large amount of data with Backbone? 使用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? 而不是大量的子视图使用一个视图并迭代模板中的数据可能是一个可能的解决方案,但是感觉你没有充分利用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? 您有什么看法,您认为它与事件的声明有关,还是Backbone的实施泄露了记忆?

Thanks in advance 提前致谢

Memory leaks are a common problem in Javascript apps in general. 内存泄漏是Javascript应用程序中的常见问题。 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. 它通常不是浏览器有问题,而是通过使用回调函数在Javascript中处理事件绑定的方式。

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/ 我写了一篇文章,讨论了这个问题,提出了处理问题的建议,特别是有关意见的建议: http//lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-应用/

Be sure to read the comments, too. 一定要阅读评论。 There are some other great suggestions for handling memory leaks in there. 还有其他一些处理内存泄漏的好建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM