Flex 3 Module的一个诡异bug

本文探讨了使用ModuleManager加载Module时遇到的所有事件无法触发的问题。分析表明,局部定义的IModuleInfo对象可能导致事件监听器被垃圾回收。解决方法是避免使用局部变量声明IModuleInfo对象。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

表现:
使用ModuleManager去加载一个Module的时候, 所有的事件都激发不了.

代码:

  1.                 var testModule:IModuleInfo = ModuleManager.getModule('modules/pub/User.swf');
  2.                 testModule.addEventListener(ModuleEvent.READY,onModuleReady);
  3.                 testModule.addEventListener(ModuleEvent.SETUP, onModuleSetup);
  4.                 testModule.addEventListener(ModuleEvent.PROGRESS,onModuleLoading);
  5.                 testModule.load();

打个赌,  ModuleEvent里所有的事件都不会被激发.


原因:

addEventListener之后, testModule的Event Listeners就可能被GC了.




解决:

不要声明局部IModuleInfo对象.


相关链接:
http://bugs.adobe.com/jira/browse/SDK-14021
https://bugs.adobe.com/jira/browse/SDK-11389

Gaurav Jain 同学说: 
"References to IModuleInfo must be maintained to keep the event listeneres alive. If the IModuleInfo is defined in function local scope the event listeners may get garbage collected. "
他表示:
"This is NAB. The weak reference was a change to fix a memory leak bug ( https://bugs.adobe.com/jira/browse/SDK-9467) "

Not a bug~ 为了修复另一个bug, 牺牲这个....



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值