views:

239

answers:

2

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 the 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?

A: 

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.

fenomas
A: 

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.

Oliver
That Grant Skinner article was the most helpful in cleaning up the external AS2 files. I got the AS2 swfs to totally clean out and release system memory when running from a simple loader but not in the main AS3 application. I'm looking/trying to clean references from the AS3 main app.
puppbits
I added traces to all loops/callbacks in AS2 and ran this:for (var i in this) { trace('AS2: this - ' + i + ":" + this[i]); }for (var i in _root) { trace('AS2: _root - ' + i + ":" + _root[i]); }for (var i in MovieClip.prototype) { trace('AS2: MovieClip.prototype - ' + i + ":" + MovieClip.prototype[i]); }for (var i in Object.prototype) { trace('AS2: Object.prototype - ' + i + ":" + Object.prototype[i]); }for (var i in _global) { trace('AS2: _global - ' + i + ":" + _global[i]); }for (var i in _level) { trace('AS2: _level - ' + i + ":" + _level[i]); }}
puppbits