I have a large project built in as3. Part of its main functionality is to load and unload various as2 swfs. The problem is that the memory ins't free up once they are unloaded.
I have access to the as2 swfs code base and destroyed all objects, stopped and killed timers, listeners, removed from stage, destroyed all the MovieClip.protoypes that were created. They look to be clean as far as the AS2 debugger show no remnants of the object after the destroy function is run. In AS3 i've closed the local connection, cleaned all references/listeners to the AVM1Movie and ran Loader.unloadAndStop(). The trace out in flex says the swf was unloaded but looking at windows task manager the memory usage never drops to when it was before t开发者_如何学Pythonhe as2 swf was loaded. Each as2 swf can take up to 80 megs each time it's run so memory gets eaten up fast and loading and unloading a few as2 files.
At this point if the AS2 swfs are unloaded the only thing that I can assume that could be left is MovieClip.prototype and/or _global, _root variables add during the AS2's run time. But i've gone through those and can't find anything else that might be sticking. Has anyone ever seen problems before with the AVM1 machine not freeing up its memory?
I think you should read these articles by Grant Skinner:
http://gskinner.com/blog/archives/2006/06/as3_resource_ma.html
http://gskinner.com/blog/archives/2006/07/as3_resource_ma_1.html
http://gskinner.com/blog/archives/2006/08/as3_resource_ma_2.html
In the second one , section Issue 2: Loaded Content really points out your issue.
Is the only problem that the memory usage is not going down, or are you sure that the memory is not being freed? I'm more familiar with memory-starved mobile content, but generally speaking after Flash requests memory from the OS, it doesn't necessarily return it just because it's no longer being used.
Rather, my experience is that you load in content, and your memory usage jumps up, then you unload it and usage stays the same. Then you load in more content, and if your usage stays about the same, you know that you freed things properly before, and Flash is reusing freed memory for your new content. That's the way you generally need to test, rather than waiting for memory usage to decrease. (Although the total memory does sometimes decrease, but exactly when this happens is something it's probably best not to worry about.)
Also, you'll probably find it better to track memory usage with System.totalMemory
, rather than what shows up in the windows task manager.
精彩评论