- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我现在大部分时间都在尝试调试我的 Backbone 多页面应用程序以摆脱“僵尸”,但不幸的是没有成功。在今天之前,我什至没有意识到我有一个僵尸问题。我做错了什么?
这是我的区域经理:
var regionManager = (function() {
var currView = null;
var rm = {};
var closeView = function(view) {
if (view && view.close) {
view.close();
}
};
var openView = function(view) {
view.render();
if (view.onShow) {
view.onShow();
}
};
rm.show = function(view) {
closeView(currView);
currView = view;
openView(currView);
};
return rm;
})();
这是我的 View 清理功能:
Backbone.View.prototype.close = function() {
if (this.onClose) {
this.onClose();
}
if (this.views) {
_.invoke(this.views, 'close');
}
// Unbind any view's events.
this.off();
// Unbind any model and collection events that the view is bound to.
if (this.model) {
this.model.off(null, null, this);
}
if (this.collection) {
this.collection.off(null, null, this);
}
// Clean up the HTML.
this.$el.empty();
};
我尝试将 View el
直接附加到 body
并在 View 清理函数中使用 this.remove();
(而不是使用常见的 el: $('#content')
向其附加元素,然后通过 this.$el.empty()
进行清理),但这也不起作用。
这可能与我的“全局事件”有关:
Backbone.Events.on('letterMouseDown', this.letterMouseDown, this);
但我用 onClose 函数来处理它们:
onClose: function() {
Backbone.Events.off('letterMouseDown');
}
最佳答案
我发现的一个问题是,您的 close
函数永远不会从 View 的 el
中删除事件委托(delegate)者。 View 的事件是通过使用 jQuery 的 on
的委托(delegate)者形式来处理的。将单个事件处理程序附加到 View 的 el
。您的 close
会:
this.$el.empty();
但这只会删除内容和附加到该内容的任何事件处理程序,它对直接附加到 this.el
的处理程序没有任何作用。考虑这个最小的例子:
var V = Backbone.View.extend({
events: {
'click': 'clicked'
},
clicked: function() {
console.log('still here');
}
});
var v = new V({ el: '#el' });
v.close();
之后,单击#el
将会在控制台中抛出'still here'
,即使您认为 View 已完全清理。演示:http://jsfiddle.net/ambiguous/aqdq7pwm/
添加 undelegateEvents
调用 close
应该可以解决这个问题。
一般建议:
不要使用老式的 on
和 off
事件函数,使用listenTo
和 stopListening
反而。 listenTo
跟踪监听器上的事件,以便以后更轻松地将它们全部删除。
将您的close
简化为:
Backbone.View.prototype.close = function() {
if(this.onClose)
this.onClose();
if(this.views)
_.invoke(this.views, 'close');
this.remove();
};
不要将 View 绑定(bind)到现有的el
。让 View 创建(并拥有)自己的 el
并让调用者将该 el
放入通常的容器中:
var v = new View();
container.append(v.render().el);
模式。如果您必须附加到现有的el
,那么 View 应该使用标准实现的稍微修改版本覆盖remove
:
remove: function() {
this.$el.empty(); // Instead of removing the element.
this.undelegateEvents(); // Manually detach the event delegator.
this.stopListening();
return this;
}
关于javascript - 不可能的 Backbone 僵尸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33200663/
更新:-[NSIndexPath行]:消息发送到已释放实例0x895fe70 当我在设备上运行我的应用程序并进行分析时,它说: 将一个Objective-C消息发送到地址为0xaa722d0的已释放对
我现在大部分时间都在尝试调试我的 Backbone 多页面应用程序以摆脱“僵尸”,但不幸的是没有成功。在今天之前,我什至没有意识到我有一个僵尸问题。我做错了什么? 这是我的区域经理: var re
我确实读过这篇文章:https://blog.phusion.nl/2015/01/20/docker-and-the-pid-1-zombie-reaping-problem/ 设置一些上下文:文章
调试使用 iPhone SDK 3.x 目标构建的应用程序时是否支持 NSZombiesEnabled? 此外,如果支持的话,我可以在哪里获取支持的可能级别的列表吗? 最佳答案 是的,设备和模拟器都支
我正在尝试了解主干,并且目前正在努力尝试僵尸 View 。我已经阅读了很多有关此问题的堆栈溢出信息,但仍然无法解决。 为了简单起见,我设置了两个需要切换的 View (无数据)。 到目前为止,我所做的
我正在尝试使用 psycopg 和多处理插入和更新几百万行。查看 http://initd.org/psycopg/docs/usage.html#thread-and-process-safety
我的应用程序在 Linux 机器上进入僵尸状态,它无法被杀死并且 gdb 无法附加到它,我无法调试。现在我想知道最后调用的函数或回溯,无论如何我可以得到这个吗?/proc/pid/stat 下是否有我
我将我的程序作为守护进程运行。 父进程只等待子进程,当它意外死亡时,fork并再次等待。 for (; 1;) { if (fork() == 0) break; int sig = 0;
注意:我们使用的是 Backbone 1.0.0 我对 Backbone 比较陌生,并且打算通过前同事编写的一些代码。我不是盲目地复制粘贴东西,而是想了解他是如何做事的,这就是我开始思考处理僵尸 Vi
我的 Backbone Marionette 应用程序出现问题,我的 subview 没有被完全破坏。您如何正确销毁要替换为另一个布局/项目 View 的嵌套布局 View ? 我对 Marionet
我有两个应用程序在一个服务器上运行,它们执行 headless (headless)浏览任务。每次浏览时,Xvfb 进程并没有死,而是变成了僵尸。我可以用以下脚本确认这一点。 require 'hea
我正在尝试使用 Marionet 模块来玩 Backbone。 例如。实现“加载微调器”,正如 David Sulc 在“contact manager”应用程序中所做的那样,Firefox 的“ba
当我尝试使用 Xcode 菜单(Product - Archive)直接存档项目时,效果很好。但是当我尝试从集成菜单 (bot) 执行它时,出现了这个错误: Build operation faile
我有一个从 nib 构建的 MainWindow 类,设置如下: - (void)applicationDidFinishLaunching:(UIApplication *)application
我关注 this answer跟踪我的应用的 EXC_BAD_ACCESS。是的,我有一个僵尸物体。当我试图找出哪一行代码是错误的时,我发现所有负责任的图书馆都是基金会的。 当我尝试这样做时: Whe
我是 iOS 开发的新手,非常感谢您帮助我找出我遇到的错误的根本原因。 我尝试使用 Instruments(即 Allocations-Zombie Profiler)调试错误,但我无法理解所呈现的调
我是一名优秀的程序员,十分优秀!