`
aksoft
  • 浏览: 44189 次
  • 性别: Icon_minigender_1
  • 来自: 河北
社区版块
存档分类
最新评论

Unloading SWFs: Loader.unload() versus Loader.unloadAndStop() Methods

    博客分类:
  • AS3
阅读更多
内存确实释放了一部分。但是还有一部分会累加。
地址:http://www.flashandmath.com/intermediate/swfload/unloading.html


这样的一种情况:

使用Loader去load一个swf:

var fileURL:String = “assets/test.swf”
var swfLoader:Loader = new Loader();
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE swfLoaded);
swfLoader.load(new URLRequest(fileURL));

function swfLoaded(evt:Event):void{
addChild(swfLoader);
}


这些是加载外部swf在AS3.0中最基本的代码,如果你在舞台上有一个按钮点击时去调用 swfLoader.unload(),按道理的话应该会把加载到swfLoader里面的test.swf给清除。

问题产生: 如果test.swf中包含声音,则会出现调用unload方法后声音还是存在。

通常情况下会怀疑自己的代码是不是有问题,或者还是别的什么。。。但是即使在最简情况下也出现这样的问题,那就要追寻缘由了。在网上找了很多相关的文章,大部分都给了这个链接: http://www.gskinner.com/blog/archives/2008/04/failure_to_unlo.html gskinner,很强的团队,以后再介绍了。里面体介绍了问题出现的情况。

unload是flash player9的一个bug,出现的情况就是flash player无法回收 loader中load的元件,unload做的工作只是将load的元件移除Loader的display list(显示列表)。而只要load的swf中包含复杂的代码,或者说有任何事件侦听代码就无法使将其回收,当然也就无法回收他占用的内存。如果有大量的加载的话很有可能让程序崩溃。然而如果swf中有声音更是直接影响。总不能停止所有声音吧。

解决方法:

读gskinner的那篇文章,你会发现他并没有直接给出解决方法,只有一些建议。读了评论你会发现更是有意思,开始大部分是夸奖,到了后来却很多是抱怨,说什么只是谈,没有解决方法阿什么的,而且会发现没人说自己顺利解决了问题。看样子真是一个很大的bug。从我个人来说我试了其中的一些方法,也没有成功。但是其中有一种方法值得我们研究,叫“GC“,垃圾回收机制强行执行,有两篇文章可以参考:http://bbs.actionscript3.cn/thread-234-1-1.html 还有就是:http://www.ultrashock.com/forums/random-chat/failure-to-unload-flash-player-9s-dirty-secret-99237.html

主要代码:

package ...
{
import flash.display.Loader;
import flash.net.LocalConnection;
public class CustomLoader extends Loader
{
override public function unload():void
{
super.unload();
try
{
new LocalConnection().connect( "FORCE_GC" );
new LocalConnection().connect( "FORCE_GC" );
}
catch( err:Error )
{}
}
}
}


我试了,虽然没有成功,但是很有启发,就是使得内部抱错,然后让flash的垃圾回收机制去回收,那样就达到了清除的目的。值得研究。

我个人的解决方法:

1、如果你愿意接受失去flash player 9.0用户的风险,你可以使用adboe在flash player 10中新发布的api,Loader.unloadAndStop,可以说是对于9.0这个bug的一个郑重的补救,详细使用可以参考:http://kb.adobe.com/selfservice/viewContent.do?externalId=kb403670&sliceId=2
#

2、如果你用过AS2.0你会发现2.0中也有一个类似的这样的方法,加载使用的是loadMovie 移除用的方法叫做:unloadMovie, 而且没有像AS3.0这样的bug。由于我在给新浪做广告播放器,由于公司不可能冒险无法清除内容出错(如果用户没有flash palyer 10),所以可以接收的解决方法是有音频的广告swf使用2.0语言来发布。而我这边开发端的方法是这样:创建一个广告swf加载容器(AS2.0语言发布)专门用于加载带声音的swf,这样可以使用unloadMovie来实现无bug移除。而对于“swf加载容器”与主容器(AS3.0语言发布)的通信,则可以通过 LocalConnection 来实现两种不同虚拟机的flash版本文件之间通信,详细代码参考以下帮助文档吧(位置: Programming Actionscript 3.0 Networking and communication >Connecting to other Flash Player instance )
分享到:
评论

相关推荐

    FairyGUI-Unity-Plugin-3.4.0.zip

    - NEW: Add UIPackage.UnloadAssets and UIPackage.ReloadAssets to allow unload package resources without removing the package. - NEW: Add TransitionActionType.Text and TransitionActionType.Icon. 2.4.0...

    EurekaLog_7.5.0.0_Enterprise

    This option will switch from fast-methods to slower methods, but which take less memory. Use 0 (default) for small projects, use 1 for large projects (if ecc32 runs out of memory). 2)....Added: --el_...

    工具_Rc522_GameGuard_limit_

    Unloading modules: [ OK ][root@localhost ~]# cd /home/login./ls_up[root@localhost login]# ./ls_up[NP] [C$][S lib] Fail to load GGVer Limit at file(./gameguard/csver.cfg). Disabled GGVer limitation....

    vxbus_device_driver_developers_guide_6.9

    PART I: VXBUS FUNDAMENTALS 1 Getting Started with Device Driver Development .................................... 3 1.1 About Device Drivers ...............................................................

    R0层获取ShadowSSDT函数原始地址实例

    本实例由VS2008开发,在提供了...[ LemonInfo : UnLoading Shadow SSDT Original Address Driver... ] [ LemonInfo : 删除“符号链接”成功... ] [ LemonInfo : 删除“设备”成功... ] [ LemonInfo : 驱动卸载成功... ]

    SystemVerilog Reference Manual 3.1a(中英文版)+最新SV IEEE 标准

    Table of Contents Section 1 Introduction to SystemVerilog ...................................................................................................... 1 Section 2 Literal Values................

    Mask 98 for PRwin98

    instance of Mask will be interpreted as a command to unload it, or - In Windows 3.1, if a program item for Mask for Windows - PRWin98 has been set up in the StartUp group in Program Manager, double...

    经典小巧的表格组件 EhLib4.14

     editing, sorting, filtrations and unloading changed given on  the server back. Components do not include drivers to access to server.  To ensure functionality of components it is sufficiently to ...

    EhLib-delphi

     editing, sorting, filtrations and unloading changed given on  the server back. Components do not include drivers to access to server.  To ensure functionality of components it is sufficiently to ...

    Turbo C++ 3.0[DISK]

    unloading and reloading. (Please see UTIL.DOC for details.) NEW BGI FONTS ------------- Several new fonts have been added to the Borland Graphics Interface: Name Value Description --------------...

    Turbo C++ 3.00[DISK]

    unloading and reloading. (Please see UTIL.DOC for details.) NEW BGI FONTS ------------- Several new fonts have been added to the Borland Graphics Interface: Name Value Description --------------...

    Sql for mysql

    CHAPTER 1 Introduction to MySQL . . . . . . . . . ....1.1 Introduction ....1.2 Database, Database Server, and Database Language....1.3 The Relational Model .... ....1.5 The History of SQL ....1.6 From Monolithic via ...

    oracle truncate恢复

    3. 运行ODU,并unload数据字典。 ODU> unload dict get_bootstrap_dba: compat header size:12 CLUSTER C_USER# file_no: 1 block_no: 177 TABLE OBJ$ file_no: 1 block_no: 241 CLUSTER C_OBJ# file_no: 1 block_no...

    vmtools-linux.iso

    Unloading pcnet32 module Trying to find a suitable vmxnet module for your running kernel. The module bld-2.6.9-5.EL-i686-RHEL4 loads perfectly in the running kernel. Detected X.org version 6.8. 关闭...

    slime用户手册

    Table of Contents 1 Introduction . . . . . . . . ....2 Getting started ....Supported Platforms ....Downloading SLIME ....2.2.1 Downloading from Git ....2.2.2 Git incantations ....2.3 Installation ....2.3.1 Installing from...

    Expert.Oracle.Database.Architecture.9i.and.10g

    ■CHAPTER 15 Data Loading and Unloading 649 SQL*Loader 649 Loading Data with SQLLDR FAQs 653 SQLLDR Caveats 679 SQLLDR Summary 680 External Tables 680 Setting Up External Tables 681 Dealing with ...

    深入java虚拟机(inside the java virtual machine)

    Active versus Passive Use The Lifetime of an Object Class Instantiation Garbage Collection and Finalization of Objects Unloading and Finalization of Classes On the CD-ROM The Resources Page 8 ...

    asp在线聊天室代码(可用-亲测)--迷你聊天室

    asp在线聊天室代码(可用-亲测) <!... Response.Buffer=true %> ... <Frame name="ltop" target="ltop" scrolling="yes" noresize src="content...<body onUnload="unloading"> 抱歉,您的浏览器不支持! </HTML>

Global site tag (gtag.js) - Google Analytics