0

i have problem with memory usage in flash, I successfully unload and remove loaded SWF's from the stage but i can't remove loaded memory and also the fps is dropping down from 30 to 18.

  1. How i load the SWF in to memory

    • I have swfUrlArray Array where i keep the SWF names (addreses ex. "intro.swf").
    • I have swfModules Dictonary where i keep the loaded SWF's.

    I loading them like this:

    mLoader = new Loader();
    var mRequest:URLRequest = new URLRequest(url);
    mLoader.load(mRequest);
    mLoader.x = pozX;
    mLoader.y = pozY;
    swfModules[url] = mLoader;
    swfUrlArray.push(url);
    currentLoaded = url;
    addChild(mLoader);
    
  2. Removing the SWF's in the loop

    for(var i=0; i < swfUrlArray.length; i++) {
        if(swfModules[swfUrlArray[i]] != null) {
            swfModules[swfUrlArray[i]].unloadAndStop();
            removeChild(swfModules[swfUrlArray[i]]);
        }
        swfUrlArray=[];
    }
    

    What i suspect here is that loop is too fast to flash to unload the SWF's memory for all files at same time. Please any suggestions or ides for this problem.


2 Answers 2

1

You clear the swfUrlArray INSIDE your for loop. So it will only unloadAndStop the first, find that the length of the array is 0 and stop.

Modified code:

for(var i=0; i < swfUrlArray.length; i++) {
    if(swfModules[swfUrlArray[i]] != null) {
        swfModules[swfUrlArray[i]].unloadAndStop();
        removeChild(swfModules[swfUrlArray[i]]);
    }
}
swfUrlArray=[];

And do what @alxx says about removing the swf reference from the dictionary.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks guys, seems that have effect :), now i think that some animation is causing to rapidly rise the memory usage. I tested this with addEventListener(Event.ENTER_FRAME, enterFrameHandler); function enterFrameHandler(event:Event):void{ trace("Interval System Trace " + System.totalMemory/1024); }
0

Is swfModules a Dictionary? It seems it still holds reference for loaded swf. Use delete swfModules[url] to remove item from Dictionary.

1 Comment

I set the code like you suggested to delete the references but seems that still don't have effect, i use trace in external SWF and after unload and delete the reference of the external SWF in output still have trace comments. If you have any idea what can be please post some comment, i will continue with experimenting. Thanks agan.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.