Flex:我应该通过哪种方式添加这个事件处理程序?
我在我的 Flex 项目中经常使用工作单元模式。我将有一个类可以调用 Web 服务,将数据放入 sqlite 数据库中,使用数据刷新模型,然后引发事件。
我通常将它们称为内联并传入一些单例类:
protected function CareerSynced():void
{
var process:ProcessWorkouts = new ProcessWorkouts(_dataModel, _trainerModel, _databaseCache, _database.Conn);
process.addEventListener("AllWorkoutsProcessed", AllWorkoutsProcessed);
process.UpdateAllUnprocessed();
}
然后我会得到如下响应:
private function AllWorkoutsProcessed(event:DataReceivedEvent):void
{
//do something here
}
我的问题是,我是否正确添加了该事件侦听器?我认为我可能会导致内存泄漏,但我不确定。我也考虑过使用弱引用。我对何时使用它们感到困惑。这会是其中之一吗?
应该是这样吗?
process.addEventListener("AllWorkoutsProcessed", AllWorkoutsProcessed,false, 0, true);
I use a unit of work pattern a lot in my flex projects. I'll have a class that might call a web service, put the data in a sqlite db, refresh a model with the data then raise an event.
I usually call these inline and pass in some singleton classes:
protected function CareerSynced():void
{
var process:ProcessWorkouts = new ProcessWorkouts(_dataModel, _trainerModel, _databaseCache, _database.Conn);
process.addEventListener("AllWorkoutsProcessed", AllWorkoutsProcessed);
process.UpdateAllUnprocessed();
}
I'll then get the response like this:
private function AllWorkoutsProcessed(event:DataReceivedEvent):void
{
//do something here
}
My question is, am I adding that event listener correctly? I think I might be causing a memory leak, but I'm not sure. I've also thought about using a weak reference. I'm confused about when to use them. Would this be one of those cases?
Should it be like this?
process.addEventListener("AllWorkoutsProcessed", AllWorkoutsProcessed,false, 0, true);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我要么选择弱引用,要么删除监听器:
我可以列出我的原因,但我只会向您指出 这个。
I would either go with the weak reference or just remove the listener:
I could list out my reasons but I'll just point you to this.